From bc2981ee8fa3cba0be0d0efb1e2a2072c98ca5a0 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 17 Dec 2020 07:55:59 +0100 Subject: API change: Reverted back to original name used for .val in iterators to .ref --- examples/README.md | 2 +- examples/advanced.c | 2 +- examples/birthday.c | 4 ++-- examples/demos.c | 24 ++++++++++++------------ examples/ex_gaussian.c | 6 +++--- examples/inits.c | 10 +++++----- examples/list.c | 12 ++++++------ examples/mapmap.c | 4 ++-- examples/phonebook.c | 2 +- examples/ptr.c | 6 +++--- examples/share_ptr.c | 8 ++++---- examples/share_ptr2.c | 2 +- examples/stack.c | 2 +- examples/words.c | 6 +++--- 14 files changed, 45 insertions(+), 45 deletions(-) (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index 114f6aac..bcb6b163 100644 --- a/examples/README.md +++ b/examples/README.md @@ -72,7 +72,7 @@ int main() { cmap_vk_emplace(&vikings, look, 0)->second += 5; // update again c_foreach (k, cmap_vk, vikings) { - printf("%s of %s has %d hp\n", k.val->first.name.str, k.val->first.country.str, k.val->second); + printf("%s of %s has %d hp\n", k.ref->first.name.str, k.ref->first.country.str, k.ref->second); } cmap_vk_del(&vikings); } diff --git a/examples/advanced.c b/examples/advanced.c index 280d5ce4..931efb57 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -73,7 +73,7 @@ int main() cmap_vk_emplace(&vikings, einar, 0).first->second += 5; // again c_foreach (k, cmap_vk, vikings) { - printf("%s of %s has %d HP\n", k.val->first.name.str, k.val->first.country.str, k.val->second); + printf("%s of %s has %d HP\n", k.ref->first.name.str, k.ref->first.country.str, k.ref->second); } cmap_vk_del(&vikings); } diff --git a/examples/birthday.c b/examples/birthday.c index a13fa8c9..7ed30bf1 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -45,11 +45,11 @@ void distribution(void) float diff = (float) (clock() - now) / CLOCKS_PER_SEC; uint64_t sum = 0; - c_foreach (i, cmap_x, map) sum += i.val->second; + c_foreach (i, cmap_x, map) sum += i.ref->second; sum /= map.size; c_foreach (i, cmap_x, map) - printf("%u: %zu - %zu\n", i.val->first, i.val->second, sum); + printf("%u: %zu - %zu\n", i.ref->first, i.ref->second, sum); printf("%.02f\n", diff); } diff --git a/examples/demos.c b/examples/demos.c index f5df2c00..cf32ca9d 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -72,7 +72,7 @@ void vectordemo2() cvec_str_sort(&names); // Sort the array c_foreach (i, cvec_str, names) - printf("sorted: %s\n", i.val->str); + printf("sorted: %s\n", i.ref->str); cvec_str_del(&names); } @@ -87,19 +87,19 @@ void listdemo1() for (int i = 100; i < 110; ++i) clist_ix_push_back(&nums2, i); c_foreach (i, clist_ix, nums) - printf("value: %d\n", *i.val); + printf("value: %d\n", *i.ref); /* merge/append nums2 to nums */ clist_ix_splice_front(&nums, &nums2); c_foreach (i, clist_ix, nums) - printf("spliced: %d\n", *i.val); + printf("spliced: %d\n", *i.ref); - *clist_ix_find(&nums, 100).val *= 10; + *clist_ix_find(&nums, 100).ref *= 10; clist_ix_sort(&nums); // Sort the array clist_ix_remove(&nums, 105); clist_ix_pop_front(&nums); clist_ix_push_front(&nums, -99); c_foreach (i, clist_ix, nums) - printf("sorted: %d\n", *i.val); + printf("sorted: %d\n", *i.ref); clist_ix_del(&nums); } @@ -113,7 +113,7 @@ void setdemo1() cset_i_insert(&nums, 11); c_foreach (i, cset_i, nums) - printf("set: %d\n", *i.val); + printf("set: %d\n", *i.ref); cset_i_del(&nums); } @@ -142,12 +142,12 @@ void mapdemo2() cmap_si_put(&nums, "Groovy", 200); // overwrite previous // iterate the map: - for (cmap_si_iter_t i = cmap_si_begin(&nums); i.val != cmap_si_end(&nums).val; cmap_si_next(&i)) - printf("long: %s: %d\n", i.val->first.str, i.val->second); + for (cmap_si_iter_t 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: c_foreach (i, cmap_si, nums) - printf("short: %s: %d\n", i.val->first.str, i.val->second); + printf("short: %s: %d\n", i.ref->first.str, i.ref->second); cmap_si_del(&nums); } @@ -164,13 +164,13 @@ void mapdemo3() cmap_str_put(&table, "Sunny", "day"); cmap_str_value_t *e = cmap_str_find(&table, "Make"); c_foreach (i, cmap_str, table) - printf("entry: %s: %s\n", i.val->first.str, i.val->second.str); + printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str); printf("size %zu: remove: Make: %s\n", cmap_size(table), e->second.str); cmap_str_erase(&table, "Make"); printf("size %zu\n", cmap_size(table)); c_foreach (i, cmap_str, table) - printf("entry: %s: %s\n", i.val->first.str, i.val->second.str); + printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str); cmap_str_del(&table); // frees key and value cstrs, and hash table. } @@ -193,7 +193,7 @@ void arraydemo1() printf("%f\n", *carray3f_at(&a3, 5, 4, 3)); // lookup a3[5][4][3] (=10.2f) c_foreach (i, carray3f, a3) - *i.val = 1.0f; + *i.ref = 1.0f; printf("%f\n", *carray3f_at(&a3, 29, 19, 9)); carray2f_del(&a2); // does nothing, since it is a sub-array. diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 0fed913f..5357a2f8 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -38,16 +38,16 @@ int main() // Transfer map to vec and sort it by map keys. cvec_e vhist = cvec_e_init(); c_foreach (i, cmap_i, mhist) - cvec_e_push_back(&vhist, *i.val); + cvec_e_push_back(&vhist, *i.ref); cvec_e_sort(&vhist); // Print the gaussian bar chart cstr_t bar = cstr_init(); c_foreach (i, cvec_e, vhist) { - size_t n = (size_t) (i.val->second * StdDev * Scale * 2.5 / N); + size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / N); if (n > 0) { cstr_resize(&bar, n, '*'); - printf("%4d %s\n", i.val->first, bar.str); + printf("%4d %s\n", i.ref->first, bar.str); } } // Cleanup diff --git a/examples/inits.c b/examples/inits.c index e358b466..4ce1421a 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -26,7 +26,7 @@ int main(void) cvec_f floats = cvec_inits; c_push_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f}); - c_foreach (i, cvec_f, floats) printf("%.1f ", *i.val); + c_foreach (i, cvec_f, floats) printf("%.1f ", *i.ref); puts(""); // CVEC PRIORITY QUEUE @@ -53,7 +53,7 @@ int main(void) }); c_foreach (i, cmap_id, idnames) - printf("%d: %s\n", i.val->first, i.val->second.str); + printf("%d: %s\n", i.ref->first, i.ref->second.str); puts(""); cmap_id_del(&idnames); @@ -76,7 +76,7 @@ int main(void) cmap_cnt_emplace(&countries, "Finland", 0).first->second += 20; c_foreach (i, cmap_cnt, countries) - printf("%s: %d\n", i.val->first.str, i.val->second); + printf("%s: %d\n", i.ref->first.str, i.ref->second); puts(""); cmap_cnt_del(&countries); @@ -92,7 +92,7 @@ int main(void) cvec_ip_sort(&pairs1); c_foreach (i, cvec_ip, pairs1) - printf("(%d %d) ", i.val->x, i.val->y); + printf("(%d %d) ", i.ref->x, i.ref->y); puts(""); cvec_ip_del(&pairs1); @@ -108,7 +108,7 @@ int main(void) clist_ip_sort(&pairs2); c_foreach (i, clist_ip, pairs2) - printf("(%d %d) ", i.val->x, i.val->y); + printf("(%d %d) ", i.ref->x, i.ref->y); puts(""); clist_ip_del(&pairs2); } \ No newline at end of file diff --git a/examples/list.c b/examples/list.c index a838b3bd..d65da22b 100644 --- a/examples/list.c +++ b/examples/list.c @@ -17,24 +17,24 @@ int main() { double sum = 0.0; printf("sumarize %d:\n", m); c_foreach (i, clist_fx, list) - sum += *i.val; + sum += *i.ref; printf("sum %f\n\n", sum); k = 0; c_foreach (i, clist_fx, list) - if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break; + if (++k <= 10) printf("%8d: %10f\n", k, *i.ref); else break; puts("sort"); clist_fx_sort(&list); // mergesort O(n*log n) puts("sorted"); k = 0; c_foreach (i, clist_fx, list) - if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break; + if (++k <= 10) printf("%8d: %10f\n", k, *i.ref); else break; puts(""); clist_fx_clear(&list); c_push_items(&list, clist_fx, {10, 20, 30, 40, 30, 50}); - c_foreach (i, clist_fx, list) printf(" %g", *i.val); + c_foreach (i, clist_fx, list) printf(" %g", *i.ref); puts(""); int removed = clist_fx_remove(&list, 30); @@ -44,11 +44,11 @@ int main() { clist_fx_iter_t it = clist_fx_before_begin(&list); printf("Full: "); c_foreach (i, clist_fx, list) - printf(" %g", *i.val); + printf(" %g", *i.ref); for (int i=0; i<4; ++i) clist_fx_next(&it); printf("\nSubs: "); c_foreach (i, clist_fx, it, clist_fx_end(&list)) - printf(" %g", *i.val); + printf(" %g", *i.ref); puts(""); clist_fx_del(&list); } \ No newline at end of file diff --git a/examples/mapmap.c b/examples/mapmap.c index 2ee46e8f..1128387d 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -19,8 +19,8 @@ int main(void) { cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj2", "Wind"); // Update c_foreach (i, cmap_cfg, config) - c_foreach (j, cmap_str, i.val->second) - printf("%s: %s - %s (%u)\n", i.val->first.str, j.val->first.str, j.val->second.str, i.val->second.bucket_count); + c_foreach (j, cmap_str, i.ref->second) + printf("%s: %s - %s (%u)\n", i.ref->first.str, j.ref->first.str, j.ref->second.str, i.ref->second.bucket_count); cmap_cfg_del(&config); } \ No newline at end of file diff --git a/examples/phonebook.c b/examples/phonebook.c index 9eaa2933..91d01072 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -30,7 +30,7 @@ using_cmap_str(); void print_phone_book(cmap_str phone_book) { c_foreach (i, cmap_str, phone_book) - printf("%s\t- %s\n", i.val->first.str, i.val->second.str); + printf("%s\t- %s\n", i.ref->first.str, i.ref->second.str); } int main(int argc, char **argv) diff --git a/examples/ptr.c b/examples/ptr.c index 6fbc74d6..b32fdb33 100644 --- a/examples/ptr.c +++ b/examples/ptr.c @@ -39,21 +39,21 @@ int main() { puts("cvec of Person:"); cvec_pe_sort(&vec); c_foreach (i, cvec_pe, vec) - printf(" %s %s\n", i.val->name.str, i.val->last.str); + printf(" %s %s\n", i.ref->name.str, i.ref->last.str); cvec_pu uvec = cvec_inits; for (int i=0;i<6; i+=2) cvec_pu_push_back(&uvec, Person_make(c_new(Person), names[i], names[i+1])); puts("cvec of cptr:"); cvec_pu_sort(&uvec); c_foreach (i, cvec_pu, uvec) - printf(" %s %s\n", (*i.val)->name.str, (*i.val)->last.str); + printf(" %s %s\n", (*i.ref)->name.str, (*i.ref)->last.str); cvec_ps svec = cvec_inits; for (int i=0;i<6; i+=2) cvec_ps_push_back(&svec, csptr_ps_from(Person_make(c_new(Person), names[i], names[i+1]))); puts("cvec of csptr:"); cvec_ps_sort(&svec); c_foreach (i, cvec_ps, svec) - printf(" %s %s\n", (*i.val).get->name.str, (*i.val).get->last.str); + printf(" %s %s\n", (*i.ref).get->name.str, (*i.ref).get->last.str); csptr_ps x = csptr_ps_share(svec.data[1]); diff --git a/examples/share_ptr.c b/examples/share_ptr.c index d851fc58..2ec2470e 100644 --- a/examples/share_ptr.c +++ b/examples/share_ptr.c @@ -41,7 +41,7 @@ int main() { cvec_pe_push_back(&vec, csptr_pe_share(p)); // Don't forget to share! } c_foreach (i, clist_pe, queue) - printf(" %s\n", i.val->get->name.str); + printf(" %s\n", i.ref->get->name.str); puts("Sort and pop 3:"); clist_pe_sort(&queue); @@ -53,16 +53,16 @@ int main() { puts("Sorted queue:"); c_foreach (i, clist_pe, queue) - printf(" %s\n", i.val->get->name.str); + printf(" %s\n", i.ref->get->name.str); puts("Sorted vec:"); c_foreach (i, cvec_pe, vec) - printf(" %s\n", i.val->get->name.str); + printf(" %s\n", i.ref->get->name.str); Person lost; Person_make(&lost, "Name 5", "Last 5"); csptr_pe ptmp = {&lost, NULL}; // share pointer without counter - OK. clist_pe_iter_t lit = clist_pe_find(&queue, ptmp); Person_del(&lost); - if (lit.val) printf("Found: %s\n", lit.val->get->name.str); + if (lit.ref) printf("Found: %s\n", lit.ref->get->name.str); printf("use %ld\n", *joe.use_count); csptr_pe_del(&joe); diff --git a/examples/share_ptr2.c b/examples/share_ptr2.c index abb58705..65240969 100644 --- a/examples/share_ptr2.c +++ b/examples/share_ptr2.c @@ -25,6 +25,6 @@ int main() { cstr_from_fmt("Last %d", (i * 9) % 10)))); } c_foreach (i, cmap_ps, map) - printf(" %d: %s\n", i.val->first, i.val->second.get->name.str); + printf(" %d: %s\n", i.ref->first, i.ref->second.get->name.str); cmap_ps_del(&map); } \ No newline at end of file diff --git a/examples/stack.c b/examples/stack.c index f65b9243..3bcf05dd 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -21,7 +21,7 @@ int main() { cstack_i_pop(&stack); c_foreach (i, cstack_i, stack) - printf(" %d", *i.val); + printf(" %d", *i.ref); puts(""); printf("top: %d\n", *cstack_i_top(&stack)); } \ No newline at end of file diff --git a/examples/words.c b/examples/words.c index 7017cebb..7e80c452 100644 --- a/examples/words.c +++ b/examples/words.c @@ -18,7 +18,7 @@ int main1() }); clist_str_push_back(&lwords, cstr_from_fmt("%f", 123897.0 / 23.0)); c_foreach (w, clist_str, lwords) - printf("%s\n", w.val->str); + printf("%s\n", w.ref->str); puts(""); cvec_str words = cvec_inits; @@ -29,10 +29,10 @@ int main1() cmap_si word_map = cmap_inits; c_foreach (w, cvec_str, words) - cmap_si_emplace(&word_map, w.val->str, 0).first->second += 1; + cmap_si_emplace(&word_map, w.ref->str, 0).first->second += 1; c_foreach (i, cmap_si, word_map) { - printf("%d occurrences of word '%s'\n", i.val->second, i.val->first.str); + printf("%d occurrences of word '%s'\n", i.ref->second, i.ref->first.str); } cmap_si_del(&word_map); -- cgit v1.2.3