diff options
| author | Tyge Løvset <[email protected]> | 2021-10-29 16:24:50 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-10-29 16:24:50 +0200 |
| commit | 9708235ec4147d2c0428c9ae5186fad452b116ad (patch) | |
| tree | 523a12b1ebee4a138e12c02c13c0a38d5f818f93 /examples | |
| parent | 0205c4913430aa54eb0536eb1621287da719be1f (diff) | |
| download | STC-modified-9708235ec4147d2c0428c9ae5186fad452b116ad.tar.gz STC-modified-9708235ec4147d2c0428c9ae5186fad452b116ad.zip | |
Renamed ..._value_t -> ..._value, etc. Deprecated, still works for cvec, cdeq, cmap, csmap, cslist
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/astar.c | 2 | ||||
| -rw-r--r-- | examples/csmap_erase.c | 4 | ||||
| -rw-r--r-- | examples/csmap_find.c | 11 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 10 | ||||
| -rw-r--r-- | examples/csset_erase.c | 2 | ||||
| -rw-r--r-- | examples/demos.c | 13 | ||||
| -rw-r--r-- | examples/ex_gauss2.c | 2 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/list_erase.c | 4 | ||||
| -rw-r--r-- | examples/list_splice.c | 2 | ||||
| -rw-r--r-- | examples/mapmap.c | 2 | ||||
| -rw-r--r-- | examples/mmap.c | 2 | ||||
| -rw-r--r-- | examples/new_deq.c | 43 | ||||
| -rw-r--r-- | examples/new_pque.c | 62 |
15 files changed, 81 insertions, 82 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 0466e0da..1c5da926 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -57,7 +57,7 @@ int main() cmap_vk_emplace_or_assign(&vikings, bjorn, 10); VikingRaw einar = {"Einar", "Norway"}; - cmap_vk_value_t *e = cmap_vk_find(&vikings, einar).ref; + cmap_vk_value *e = cmap_vk_find(&vikings, einar).ref; e->second += 3; // add 3 hp points to Einar cmap_vk_emplace(&vikings, einar, 0).ref->second += 5; // add 5 more to Einar diff --git a/examples/astar.c b/examples/astar.c index 651886e9..04c18113 100644 --- a/examples/astar.c +++ b/examples/astar.c @@ -107,7 +107,7 @@ astar(cstr* maze, int width) int new_cost = *csmap_pcost_at(&costs, current);
if (maze->str[point_index(&next)] != '#')
{
- csmap_pcost_value_t *cost = csmap_pcost_get(&costs, next);
+ csmap_pcost_value *cost = csmap_pcost_get(&costs, next);
if (cost == NULL || new_cost < cost->second)
{
csmap_pcost_insert(&costs, next, new_cost);
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index 993f1837..bbb69a35 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -47,8 +47,8 @@ int main() puts("Starting data of map m2 is:"); printmap(m2); - mymap_iter_t it1 = mymap_advance(mymap_begin(&m2), 1); - mymap_iter_t it2 = mymap_find(&m2, mymap_back(&m2)->first); + mymap_iter it1 = mymap_advance(mymap_begin(&m2), 1); + mymap_iter it2 = mymap_find(&m2, mymap_back(&m2)->first); // The 2nd member function removes elements // in the range [First, Last) mymap_erase_range(&m2, it1, it2); diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 39ffd975..977ae6ca 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -7,12 +7,12 @@ #define i_tag istr #include <stc/csmap.h> -#define i_val csmap_istr_rawvalue_t +#define i_val csmap_istr_rawvalue #define i_cmp c_no_compare #define i_tag istr #include <stc/cvec.h> -void print_elem(csmap_istr_rawvalue_t p) { +void print_elem(csmap_istr_rawvalue p) { printf("(%d, %s) ", p.first, p.second); } @@ -29,11 +29,10 @@ void print_elem(csmap_istr_rawvalue_t p) { using_print_collection(csmap_istr) using_print_collection(cvec_istr) - -void findit(csmap_istr c, csmap_istr_key_t val) +void findit(csmap_istr c, csmap_istr_key val) { printf("Trying find() on value %d\n", val); - csmap_istr_iter_t result = csmap_istr_find(&c, val); // prefer contains() or get() + csmap_istr_iter result = csmap_istr_find(&c, val); // prefer contains() or get() if (result.ref != csmap_istr_end(&c).ref) { printf("Element found: "); print_elem(csmap_istr_value_toraw(result.ref)); puts(""); } else { @@ -50,7 +49,7 @@ int main() puts("The starting map m1 is (key, value):"); print_collection_csmap_istr(m1); - typedef cvec_istr_value_t pair; + typedef cvec_istr_value pair; cvec_istr_emplace_back(&v, (pair){43, "Tc"}); cvec_istr_emplace_back(&v, (pair){41, "Nb"}); cvec_istr_emplace_back(&v, (pair){46, "Pd"}); diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 939f2eca..3e908164 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -14,7 +14,7 @@ #define i_tag istr // Map of int => cstr
#include <stc/csmap.h>
-#define i_val csmap_ii_rawvalue_t
+#define i_val csmap_ii_rawvalue
#define i_cmp c_no_compare
#define i_tag ii
#include <stc/cvec.h>
@@ -42,9 +42,9 @@ int main() print_ii(m1);
// intentionally attempt a duplicate, single element
- csmap_ii_result_t ret = csmap_ii_insert(&m1, 1, 111);
+ csmap_ii_result ret = csmap_ii_insert(&m1, 1, 111);
if (!ret.inserted) {
- csmap_ii_value_t pr = *ret.ref;
+ csmap_ii_value pr = *ret.ref;
puts("Insert failed, element with key value 1 already exists.");
printf(" The existing element is (%d, %d)\n", pr.first, pr.second);
}
@@ -63,7 +63,7 @@ int main() // The templatized version inserting a jumbled range
c_auto (csmap_ii, m2)
c_auto (cvec_ii, v) {
- typedef cvec_ii_value_t ipair;
+ typedef cvec_ii_value ipair;
cvec_ii_push_back(&v, (ipair){43, 294});
cvec_ii_push_back(&v, (ipair){41, 262});
cvec_ii_push_back(&v, (ipair){45, 330});
@@ -83,7 +83,7 @@ int main() // The templatized versions move-constructing elements
c_auto (csmap_istr, m3) {
- csmap_istr_value_t ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
+ csmap_istr_value ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
csmap_istr_insert(&m3, ip1.first, cstr_move(&ip1.second));
diff --git a/examples/csset_erase.c b/examples/csset_erase.c index 6104a2b2..95145ed8 100644 --- a/examples/csset_erase.c +++ b/examples/csset_erase.c @@ -13,7 +13,7 @@ int main() puts("");
int val = 64;
- csset_int_iter_t it;
+ csset_int_iter it;
printf("Show values >= %d:\n", val);
it = csset_int_lower_bound(&set, val);
diff --git a/examples/demos.c b/examples/demos.c index ab1a95ff..49ac8486 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -59,7 +59,7 @@ void vectordemo1() void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_autovar (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
+ c_auto (cvec_str, names) {
cvec_str_emplace_back(&names, "Mary");
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
@@ -79,8 +79,7 @@ void vectordemo2() void listdemo1()
{
printf("\nLISTDEMO1\n");
- c_autovar (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
- c_autovar (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
+ c_auto (clist_ix, nums, nums2)
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -95,7 +94,7 @@ void listdemo1() *clist_ix_find(&nums, 104).ref += 50;
clist_ix_remove(&nums, 103);
- clist_ix_iter_t it = clist_ix_begin(&nums);
+ clist_ix_iter it = clist_ix_begin(&nums);
clist_ix_erase_range(&nums, clist_ix_advance(it, 5), clist_ix_advance(it, 15));
clist_ix_pop_front(&nums);
clist_ix_push_back(&nums, -99);
@@ -145,14 +144,14 @@ void mapdemo1() void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_autovar (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
+ c_auto (cmap_si, nums)
{
cmap_si_emplace_or_assign(&nums, "Hello", 64);
cmap_si_emplace_or_assign(&nums, "Groovy", 121);
cmap_si_emplace_or_assign(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
+ for (cmap_si_iter i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
printf("long: %s: %d\n", i.ref->first.str, i.ref->second);
// or rather use the short form:
@@ -172,7 +171,7 @@ void mapdemo3() cmap_str_emplace(&table, "Map", "test");
cmap_str_emplace(&table, "Make", "my");
cmap_str_emplace(&table, "Sunny", "day");
- cmap_str_iter_t it = cmap_str_find(&table, "Make");
+ cmap_str_iter it = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
printf("size %zu: remove: Make: %s\n", cmap_str_size(table), it.ref->second.str);
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c index a57251bc..b3890ecf 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -22,7 +22,6 @@ int main() // Create and init histogram map with defered destruct
c_auto (csmap_int, mhist)
- c_auto (cstr, bar)
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -30,6 +29,7 @@ int main() }
// Print the gaussian bar chart
+ c_auto (cstr, bar)
c_foreach (i, csmap_int, mhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
diff --git a/examples/list.c b/examples/list.c index 30923e8b..d0d377f3 100644 --- a/examples/list.c +++ b/examples/list.c @@ -44,7 +44,7 @@ int main() { clist_fx_insert(&list, clist_fx_begin(&list), 5); // same as push_front()
clist_fx_push_back(&list, 500);
clist_fx_push_front(&list, 1964);
- clist_fx_iter_t it = clist_fx_begin(&list);
+ clist_fx_iter it = clist_fx_begin(&list);
printf("Full: ");
c_foreach (i, clist_fx, list)
printf(" %g", *i.ref);
diff --git a/examples/list_erase.c b/examples/list_erase.c index c1e5ab61..e2db62d5 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -11,11 +11,11 @@ int main () {
c_apply(clist_i, push_back, &L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
- clist_i_iter_t it = clist_i_begin(&L); // ^
+ clist_i_iter it = clist_i_begin(&L); // ^
clist_i_next(&it);
it = clist_i_erase_at(&L, it); // 10 30 40 50
// ^
- clist_i_iter_t end = clist_i_end(&L); //
+ clist_i_iter end = clist_i_end(&L); //
clist_i_next(&it);
it = clist_i_erase_range(&L, it, end); // 10 30
// ^
diff --git a/examples/list_splice.c b/examples/list_splice.c index 517cbcce..f1049288 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -22,7 +22,7 @@ int main () print_ilist("list1:", list1); print_ilist("list2:", list2); - clist_i_iter_t it = clist_i_advance(clist_i_begin(&list1), 2); + clist_i_iter it = clist_i_advance(clist_i_begin(&list1), 2); it = clist_i_splice(&list1, it, &list2); puts("After splice"); diff --git a/examples/mapmap.c b/examples/mapmap.c index 184a7a7d..047132d1 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -19,7 +19,7 @@ void add(csmap_conf* map, const char* section, const char* entry, const char* va bool contains(csmap_conf* map, const char* section, const char* entry)
{
- csmap_conf_value_t *val = csmap_conf_get(map, section);
+ csmap_conf_value *val = csmap_conf_get(map, section);
return val && csmap_sect_get(&val->second, entry);
}
diff --git a/examples/mmap.c b/examples/mmap.c index 8ecaa6f5..e3c876ce 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -56,7 +56,7 @@ int main() print(mmap);
// find and erase a specific entry
- clist_str_iter_t pos;
+ clist_str_iter pos;
c_foreach (e, csmap_mult, mmap)
if ((pos = clist_str_find(&e.ref->second, "bar")).ref != clist_str_end(&e.ref->second).ref) {
clist_str_erase_at(&e.ref->second, pos);
diff --git a/examples/new_deq.c b/examples/new_deq.c index 7d30343f..0b41b167 100644 --- a/examples/new_deq.c +++ b/examples/new_deq.c @@ -36,25 +36,26 @@ int point_compare(const Point* a, const Point* b) { int main()
{
- cdeq_i32 vec = cdeq_i32_init();
- cdeq_i32_push_back(&vec, 123);
- cdeq_i32_del(&vec);
-
- cdeq_float fvec = cdeq_float_init();
- cdeq_float_push_back(&fvec, 123.3);
- cdeq_float_del(&fvec);
-
- cdeq_pnt pvec = cdeq_pnt_init();
- cdeq_pnt_push_back(&pvec, (Point){42, 14});
- cdeq_pnt_push_back(&pvec, (Point){32, 94});
- cdeq_pnt_push_front(&pvec, (Point){62, 81});
- cdeq_pnt_sort(&pvec);
- c_foreach (i, cdeq_pnt, pvec)
- printf(" (%d %d)", i.ref->x, i.ref->y);
- puts("");
- cdeq_pnt_del(&pvec);
-
- cdeq_str svec = cdeq_str_init();
- cdeq_str_emplace_back(&svec, "Hello, friend");
- cdeq_str_del(&svec);
+ c_auto (cdeq_i32, vec)
+ {
+ cdeq_i32_push_back(&vec, 123);
+ }
+ c_auto (cdeq_float, fvec)
+ {
+ cdeq_float_push_back(&fvec, 123.3);
+ }
+ c_auto (cdeq_pnt, pvec)
+ {
+ cdeq_pnt_push_back(&pvec, (Point){42, 14});
+ cdeq_pnt_push_back(&pvec, (Point){32, 94});
+ cdeq_pnt_push_front(&pvec, (Point){62, 81});
+ cdeq_pnt_sort(&pvec);
+ c_foreach (i, cdeq_pnt, pvec)
+ printf(" (%d %d)", i.ref->x, i.ref->y);
+ puts("");
+ }
+ c_auto (cdeq_str, svec)
+ {
+ cdeq_str_emplace_back(&svec, "Hello, friend");
+ }
}
\ No newline at end of file diff --git a/examples/new_pque.c b/examples/new_pque.c index 8335e46e..94a12fbd 100644 --- a/examples/new_pque.c +++ b/examples/new_pque.c @@ -30,36 +30,36 @@ int Point_cmp(const Point* a, const Point* b) { int main()
{
- cstack_int istk = cstack_int_init();
- cstack_int_push(&istk, 123);
- cstack_int_push(&istk, 321);
- // print
- c_foreach (i, cstack_int, istk)
- printf(" %d", *i.ref);
- cstack_int_del(&istk);
- puts("");
-
- cpque_pnt pque = cpque_pnt_init();
- cpque_pnt_push(&pque, (Point){23, 80});
- cpque_pnt_push(&pque, (Point){12, 32});
- cpque_pnt_push(&pque, (Point){54, 74});
- cpque_pnt_push(&pque, (Point){12, 62});
- // print
- while (!cpque_pnt_empty(pque)) {
- cpque_pnt_value_t *v = cpque_pnt_top(&pque);
- printf(" (%d,%d)", v->x, v->y);
- cpque_pnt_pop(&pque);
+ c_auto (cstack_int, istk)
+ {
+ cstack_int_push(&istk, 123);
+ cstack_int_push(&istk, 321);
+ // print
+ c_foreach (i, cstack_int, istk)
+ printf(" %d", *i.ref);
+ puts("");
+ }
+ c_auto (cpque_pnt, pque)
+ {
+ cpque_pnt_push(&pque, (Point){23, 80});
+ cpque_pnt_push(&pque, (Point){12, 32});
+ cpque_pnt_push(&pque, (Point){54, 74});
+ cpque_pnt_push(&pque, (Point){12, 62});
+ // print
+ while (!cpque_pnt_empty(pque)) {
+ cpque_pnt_value *v = cpque_pnt_top(&pque);
+ printf(" (%d,%d)", v->x, v->y);
+ cpque_pnt_pop(&pque);
+ }
+ puts("");
+ }
+ c_auto (cpque_int, ique)
+ {
+ cpque_int_push(&ique, 123);
+ cpque_int_push(&ique, 321);
+ // print
+ for (int i=0; i<cpque_int_size(ique); ++i)
+ printf(" %d", ique.data[i]);
+ puts("");
}
- // free
- cpque_pnt_del(&pque);
- puts("");
-
- cpque_int ique = cpque_int_init();
- cpque_int_push(&ique, 123);
- cpque_int_push(&ique, 321);
- // print
- for (int i=0; i<cpque_int_size(ique); ++i)
- printf(" %d", ique.data[i]);
- cpque_int_del(&ique);
- puts("");
}
|
