From 11db093d6037ed8737cfa4fb7ed44b9e09deef33 Mon Sep 17 00:00:00 2001 From: tylo Date: Mon, 7 Sep 2020 10:15:41 +0200 Subject: Added back cmap insert() --- examples/birthday.c | 4 ++-- examples/ex_gaussian.c | 2 +- examples/geek1.c | 4 ++-- examples/geek2.c | 3 ++- examples/geek3.c | 8 ++++---- examples/inits.c | 8 ++++---- examples/mapmap.c | 14 +++++++------- examples/words.c | 2 +- 8 files changed, 23 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/birthday.c b/examples/birthday.c index bf807e67..5f5174d6 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -21,7 +21,7 @@ void repeats(void) clock_t now = clock(); for (size_t i = 0; i < N; ++i) { uint64_t k = crand_i64(&rng) & mask; - int v = ++cmap_ic_emplace(&m, k, 0).item->value; + int v = ++cmap_ic_insert(&m, k, 0).item->value; if (v > 1) printf("%zu: %llx - %d\n", i, k, v); } float diff = (float) (clock() - now) / CLOCKS_PER_SEC; @@ -40,7 +40,7 @@ void distribution(void) clock_t now = clock(); crand_uniform_i32_t dist = crand_uniform_i32_init(rng, 0, M); for (size_t i = 0; i < N; ++i) { - ++cmap_x_emplace(&map, crand_uniform_i32(&dist), 0).item->value; + ++cmap_x_insert(&map, crand_uniform_i32(&dist), 0).item->value; } float diff = (float) (clock() - now) / CLOCKS_PER_SEC; diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index d2da77d9..dd3a61ac 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -32,7 +32,7 @@ int main() cmap_i mhist = cmap_ini; for (size_t i = 0; i < N; ++i) { int index = round( crand_normal_f64(&dist) ); - cmap_i_emplace(&mhist, index, 0).item->value += 1; + cmap_i_insert(&mhist, index, 0).item->value += 1; } // Transfer map to vec and sort it by map keys. diff --git a/examples/geek1.c b/examples/geek1.c index 194b92da..fdc6d84c 100644 --- a/examples/geek1.c +++ b/examples/geek1.c @@ -21,7 +21,7 @@ int findMaximumPairs(int a[], int n, int k) // Hash-table cmap_ii hash = cmap_ini; for (int i = 0; i < n; i++) { - cmap_ii_emplace(&hash, a[i] % k, 0).item->value++; + cmap_ii_insert(&hash, a[i] % k, 0).item->value++; } int count = 0; @@ -39,7 +39,7 @@ int findMaximumPairs(int a[], int n, int k) int second = k - it.item->key; cmap_ii_entry_t *hf = cmap_ii_find(&hash, first), - *hs = cmap_ii_emplace(&hash, second, 0).item; + *hs = cmap_ii_insert(&hash, second, 0).item; // Check for minimal occurrence if (hf->value < hs->value) { // Take the minimal diff --git a/examples/geek2.c b/examples/geek2.c index 0e8b384a..01b5c367 100644 --- a/examples/geek2.c +++ b/examples/geek2.c @@ -16,7 +16,8 @@ int main() cset_str_put(&set, "You"); cset_str_put(&set, "Tube"); c_foreach (i, cset_str, set) - printf("%s ", i.item->key.str); puts(""); + printf("%s ", i.item->key.str); + puts(""); // Review some books. c_push(&book_reviews, cmap_str, c_items( diff --git a/examples/geek3.c b/examples/geek3.c index be3c8c10..29614fc7 100644 --- a/examples/geek3.c +++ b/examples/geek3.c @@ -15,10 +15,10 @@ int main () // ... cmap_si_put(&mymap, "Mars", 3396); - cmap_si_emplace(&mymap, "Saturn", 0).item->value += 272; - cmap_si_put(&mymap, "Jupiter", cmap_si_emplace(&mymap, "Saturn", 0).item->value + 9638); - cmap_si_emplace(&mymap, "Sun", 0).item->value += 1000; - cmap_si_emplace(&mymap, "Sun", 0).item->value += 1000; + cmap_si_insert(&mymap, "Saturn", 0).item->value += 272; + cmap_si_put(&mymap, "Jupiter", cmap_si_insert(&mymap, "Saturn", 0).item->value + 9638); + cmap_si_insert(&mymap, "Sun", 0).item->value += 1000; + cmap_si_insert(&mymap, "Sun", 0).item->value += 1000; c_foreach (x, cmap_si, mymap) { printf("%s: %d\n", x.item->key.str, x.item->value); diff --git a/examples/inits.c b/examples/inits.c index 16882e7a..fa9de214 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -68,10 +68,10 @@ int main(void) { {"Spain", 10}, {"France", 10}, )); - cmap_cnt_emplace(&countries, "Greenland", 0).item->value += 20; - cmap_cnt_emplace(&countries, "Sweden", 0).item->value += 20; - cmap_cnt_emplace(&countries, "Norway", 0).item->value += 20; - cmap_cnt_emplace(&countries, "Finland", 0).item->value += 20; + cmap_cnt_insert(&countries, "Greenland", 0).item->value += 20; + cmap_cnt_insert(&countries, "Sweden", 0).item->value += 20; + cmap_cnt_insert(&countries, "Norway", 0).item->value += 20; + cmap_cnt_insert(&countries, "Finland", 0).item->value += 20; c_foreach (i, cmap_cnt, countries) printf("%s: %d\n", i.item->key.str, i.item->value); diff --git a/examples/mapmap.c b/examples/mapmap.c index 6929dc69..e1e78bba 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -9,14 +9,14 @@ declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy); int main(void) { cmap_cfg config = cmap_ini; cmap_str init = cmap_ini; - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "user", init).item->value, "name", "Joe"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "user", init).item->value, "groups", "proj1,proj3"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj1", "Energy"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj2", "Windy"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj3", "Oil"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "admin", init).item->value, "employees", "2302"); + cmap_str_put(&cmap_cfg_insert(&config, "user", init).item->value, "name", "Joe"); + cmap_str_put(&cmap_cfg_insert(&config, "user", init).item->value, "groups", "proj1,proj3"); + cmap_str_put(&cmap_cfg_insert(&config, "group", init).item->value, "proj1", "Energy"); + cmap_str_put(&cmap_cfg_insert(&config, "group", init).item->value, "proj2", "Windy"); + cmap_str_put(&cmap_cfg_insert(&config, "group", init).item->value, "proj3", "Oil"); + cmap_str_put(&cmap_cfg_insert(&config, "admin", init).item->value, "employees", "2302"); - cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj2", "Wind"); // Update + cmap_str_put(&cmap_cfg_insert(&config, "group", init).item->value, "proj2", "Wind"); // Update c_foreach (i, cmap_cfg, config) c_foreach (j, cmap_str, i.item->value) diff --git a/examples/words.c b/examples/words.c index 92f98c85..af637b8d 100644 --- a/examples/words.c +++ b/examples/words.c @@ -29,7 +29,7 @@ int main1() cmap_si word_map = cmap_ini; c_foreach (w, cvec_str, words) - ++cmap_si_emplace(&word_map, w.item->str, 0).item->value; + cmap_si_insert(&word_map, w.item->str, 0).item->value += 1; c_foreach (pair, cmap_si, word_map) { printf("%d occurrences of word '%s'\n", -- cgit v1.2.3