diff options
| author | Tyge Løvset <[email protected]> | 2022-09-26 23:56:09 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-26 23:56:09 +0200 |
| commit | 60c4432678073faa271fe9b6f632c5a3789d5727 (patch) | |
| tree | af8dc7b274bf1d7ad96b7774275092a1ecbe1a03 | |
| parent | 2c31b421b6c867ab956a843dace0d95769a97667 (diff) | |
| download | STC-modified-60c4432678073faa271fe9b6f632c5a3789d5727.tar.gz STC-modified-60c4432678073faa271fe9b6f632c5a3789d5727.zip | |
Deprecated c_pair() macro. Replaced with c_PAIR(), analogous to c_ARGsv() macro which are both unsafe regarding side effects on arg.
| -rw-r--r-- | docs/carc_api.md | 6 | ||||
| -rw-r--r-- | docs/cmap_api.md | 4 | ||||
| -rw-r--r-- | docs/csmap_api.md | 4 | ||||
| -rw-r--r-- | examples/convert.c | 2 | ||||
| -rw-r--r-- | examples/csmap_erase.c | 2 | ||||
| -rw-r--r-- | examples/csmap_find.c | 4 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 2 | ||||
| -rw-r--r-- | examples/inits.c | 2 | ||||
| -rw-r--r-- | examples/new_map.c | 4 | ||||
| -rw-r--r-- | examples/new_queue.c | 23 | ||||
| -rw-r--r-- | examples/new_smap.c | 4 | ||||
| -rw-r--r-- | examples/phonebook.c | 2 | ||||
| -rw-r--r-- | examples/sidebyside.cpp | 2 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 3 |
14 files changed, 33 insertions, 31 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md index 3c2a223f..fd20ad01 100644 --- a/docs/carc_api.md +++ b/docs/carc_api.md @@ -104,18 +104,18 @@ int main() map = Stack_push(&s1, Arc_make(Map_init()))->get; // push empty map to s1. c_forlist (i, Map_raw, { {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992} }) { - Map_emplace(map, c_pair(i.ref)); // populate it. + Map_emplace(map, c_PAIR(i.ref)); // populate it. } map = Stack_push(&s1, Arc_make(Map_init()))->get; c_forlist (i, Map_raw, { {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980} }) { - Map_emplace(map, c_pair(i.ref)); + Map_emplace(map, c_PAIR(i.ref)); } // POPULATE s2: map = Stack_push(&s2, Arc_make(Map_init()))->get; c_forlist (i, Map_raw, { {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003} }) { - Map_emplace(map, c_pair(i.ref)); + Map_emplace(map, c_PAIR(i.ref)); } // Share two Maps from s1 with s2 by cloning(=sharing) the carcs: diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 25366792..863fbaf6 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -131,7 +131,7 @@ int main() {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} - }) cmap_str_emplace(&u, c_pair(i.ref)); + }) cmap_str_emplace(&u, c_PAIR(i.ref)); // Iterate and print keys and values of unordered map c_foreach (n, cmap_str, u) { @@ -174,7 +174,7 @@ int main() c_auto (cmap_id, idnames) { c_forlist (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} }) - cmap_id_emplace(&idnames, c_pair(i.ref)); + cmap_id_emplace(&idnames, c_PAIR(i.ref)); // replace existing mapped value: cmap_id_emplace_or_assign(&idnames, 110, "White"); diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 0be14605..38fd4bf4 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -117,7 +117,7 @@ int main() {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} - }) csmap_str_emplace(&colors, c_pair(i.ref)); + }) csmap_str_emplace(&colors, c_PAIR(i.ref)); // Iterate and print keys and values of sorted map c_foreach (i, csmap_str, colors) { @@ -160,7 +160,7 @@ int main() c_defer (csmap_id_drop(&idnames)) { c_forlist (i, csmap_id_raw, { {100, "Red"}, {110, "Blue"} }) - csmap_id_emplace(&idnames, c_pair(i.ref)); + csmap_id_emplace(&idnames, c_PAIR(i.ref)); // put replaces existing mapped value: csmap_id_emplace_or_assign(&idnames, 110, "White"); diff --git a/examples/convert.c b/examples/convert.c index a8260564..1372b830 100644 --- a/examples/convert.c +++ b/examples/convert.c @@ -21,7 +21,7 @@ int main() {"green", "#00ff00"}, {"blue", "#0000ff"}, {"yellow", "#ffff00"}, - }) cmap_str_emplace(&map, c_pair(i.ref)); + }) cmap_str_emplace(&map, c_PAIR(i.ref)); puts("MAP:"); c_foreach (i, cmap_str, map) diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index e99a4d7a..318d74b4 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -43,7 +43,7 @@ int main() {12, "Robert"}, {13, "Bert"}, {14, "Bobby"}, - }) mymap_emplace(&m2, c_pair(i.ref)); + }) mymap_emplace(&m2, c_PAIR(i.ref)); puts("Starting data of map m2 is:"); printmap(m2); diff --git a/examples/csmap_find.c b/examples/csmap_find.c index e7a7112c..e281a431 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -46,7 +46,7 @@ int main() c_auto (cvec_istr, v) { c_forlist (i, csmap_istr_raw, {{40, "Zr"}, {45, "Rh"}}) - csmap_istr_emplace(&m1, c_pair(i.ref)); + csmap_istr_emplace(&m1, c_PAIR(i.ref)); puts("The starting map m1 is (key, value):"); print_collection_csmap_istr(&m1); @@ -63,7 +63,7 @@ int main() print_collection_cvec_istr(&v); c_foreach (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v)) - csmap_istr_emplace(&m1, c_pair(i.ref)); + csmap_istr_emplace(&m1, c_PAIR(i.ref)); puts("The modified map m1 is (key, value):"); print_collection_csmap_istr(&m1); diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 71c8cfe9..4d4c3871 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -103,7 +103,7 @@ int main() // Insert the elements from an initializer_list c_forlist (i, csmap_ii_raw, {{ 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 }}) - csmap_ii_insert(&m4, c_pair(i.ref)); + csmap_ii_insert(&m4, c_PAIR(i.ref)); puts("After initializer_list insertion, m4 contains:"); print_ii(m4); diff --git a/examples/inits.c b/examples/inits.c index 875406e1..2e51e860 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -76,7 +76,7 @@ int main(void) {"Germany", 10}, {"Spain", 10}, {"France", 10}, - }) cmap_cnt_emplace(&countries, c_pair(i.ref)); + }) cmap_cnt_emplace(&countries, c_PAIR(i.ref)); cmap_cnt_emplace(&countries, "Greenland", 0).ref->second += 20; cmap_cnt_emplace(&countries, "Sweden", 0).ref->second += 20; diff --git a/examples/new_map.c b/examples/new_map.c index 7f12c43c..24909a7c 100644 --- a/examples/new_map.c +++ b/examples/new_map.c @@ -50,7 +50,7 @@ int main() cmap_int_insert(&map, 123, 321); c_forlist (i, cmap_pnt_raw, {{{42, 14}, 1}, {{32, 94}, 2}, {{62, 81}, 3}}) - cmap_pnt_insert(&pmap, c_pair(i.ref)); + cmap_pnt_insert(&pmap, c_PAIR(i.ref)); c_foreach (i, cmap_pnt, pmap) printf(" (%d, %d: %d)", i.ref->first.x, i.ref->first.y, i.ref->second); @@ -59,7 +59,7 @@ int main() c_forlist (i, cmap_str_raw, { {"Hello, friend", "long time no see"}, {"So long, friend", "see you around"}, - }) cmap_str_emplace(&smap, c_pair(i.ref)); + }) cmap_str_emplace(&smap, c_PAIR(i.ref)); c_forlist (i, const char*, { "Hello, friend", diff --git a/examples/new_queue.c b/examples/new_queue.c index ea68c9b9..eebf3493 100644 --- a/examples/new_queue.c +++ b/examples/new_queue.c @@ -16,29 +16,30 @@ int point_cmp(const Point* a, const Point* b) { #define i_tag pnt #include <stc/cqueue.h> +#define i_type IQ #define i_val int #include <stc/cqueue.h> int main() { - int n = 60000000; + int n = 50000000; stc64_t rng = stc64_new(time(NULL)); stc64_uniform_t dist = stc64_uniform_new(0, n); - c_auto (cqueue_int, Q) + c_auto (IQ, Q) { // Push eight million random numbers onto the queue. - for (int i=0; i<n; ++i) - cqueue_int_push(&Q, stc64_uniform(&rng, &dist)); + c_forloop (n) + IQ_push(&Q, stc64_uniform(&rng, &dist)); - // Push or pop on the queue ten million times - printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q)); - for (int i=n; i>0; --i) { + // Push or pop on the queue 50 million times + printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q)); + c_forloop (n) { int r = stc64_uniform(&rng, &dist); - if (r & 1) - cqueue_int_push(&Q, r); + if (r & 3) + IQ_push(&Q, r); else - cqueue_int_pop(&Q); + IQ_pop(&Q); } - printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q)); + printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q)); } } diff --git a/examples/new_smap.c b/examples/new_smap.c index 154b04a3..35c56b7c 100644 --- a/examples/new_smap.c +++ b/examples/new_smap.c @@ -51,7 +51,7 @@ int main() {{42, 14}, 1}, {{32, 94}, 2}, {{62, 81}, 3}, - }) PMap_insert(&pmap, c_pair(i.ref)); + }) PMap_insert(&pmap, c_PAIR(i.ref)); c_forpair (p, i, PMap, pmap) printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i); @@ -63,7 +63,7 @@ int main() {"Hello, friend", "this is the mapped value"}, {"The brown fox", "jumped"}, {"This is the time", "for all good things"}, - }) SMap_emplace(&smap, c_pair(i.ref)); + }) SMap_emplace(&smap, c_PAIR(i.ref)); c_forpair (i, j, SMap, smap) printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j)); diff --git a/examples/phonebook.c b/examples/phonebook.c index 825ef61d..be068409 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) {"Tariq Beltran", "(489) 600-7575"}, {"Laiba Juarez", "(303) 885-5692"}, {"Elliott Mooney", "(945) 616-4482"}, - }) cmap_str_emplace(&phone_book, c_pair(i.ref)); + }) cmap_str_emplace(&phone_book, c_PAIR(i.ref)); printf("Phone book:\n"); print_phone_book(phone_book); diff --git a/examples/sidebyside.cpp b/examples/sidebyside.cpp index 2578c120..35dd1a6e 100644 --- a/examples/sidebyside.cpp +++ b/examples/sidebyside.cpp @@ -48,7 +48,7 @@ int main() { c_auto (cmap_si, food) { c_forlist (i, cmap_si_raw, {{"burger", 5}, {"pizza", 12}, {"steak", 15}}) - cmap_si_emplace(&food, c_pair(i.ref)); + cmap_si_emplace(&food, c_PAIR(i.ref)); c_foreach (i, cmap_si, food) printf("%s, %d\n", cstr_str(&i.ref->first), i.ref->second); diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 1961833b..c6bf1f72 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -118,6 +118,8 @@ typedef const char* crawstr; #define c_sv2(str, n) (c_make(csview){str, n}) #define c_PRIsv ".*s" #define c_ARGsv(sv) (int)(sv).size, (sv).str +#define c_PAIR(ref) (ref)->first, (ref)->second +#define c_pair(ref) c_PAIR(ref) // [deprecated] #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) @@ -261,7 +263,6 @@ STC_INLINE void crange_next(crange_iter* it) *b = (n)*sizeof *b > (BYTES) ? c_alloc_n(type, n) : _c_b \ ; b; b != _c_b ? c_free(b) : (void)0, b = NULL) -#define c_pair(v) (v)->first, (v)->second #define c_drop(C, ...) do { c_forlist (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0) #define c_find_if(it, C, cnt, pred) do { \ |
