summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-10 20:48:44 +0200
committerTyge Løvset <[email protected]>2020-09-10 20:48:44 +0200
commit8dd8368bca262dbab39741fbbb61c16478772e4e (patch)
treefa7b82f835a002f60a70d1b1b159fbb4a26f9bf5 /examples
parent0b3e84cac29288af49bbabf2f880cd6319f9a1f3 (diff)
downloadSTC-modified-8dd8368bca262dbab39741fbbb61c16478772e4e.tar.gz
STC-modified-8dd8368bca262dbab39741fbbb61c16478772e4e.zip
Use cmap_emplace() rather than cmap_insert(). insert() is reduced to an alias of emplace() because it makes no sense using the std::unordered_map API.
Diffstat (limited to 'examples')
-rw-r--r--examples/advanced.c2
-rw-r--r--examples/birthday.c4
-rw-r--r--examples/ex_gaussian.c2
-rw-r--r--examples/geek1.c4
-rw-r--r--examples/geek2.c8
-rw-r--r--examples/geek3.c8
-rw-r--r--examples/inits.c8
-rw-r--r--examples/mapmap.c14
-rw-r--r--examples/words.c2
9 files changed, 26 insertions, 26 deletions
diff --git a/examples/advanced.c b/examples/advanced.c
index aa82e38e..0aa1600e 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -71,7 +71,7 @@ int main()
VikingVw einar = {"Einar", "Norway"};
cmap_vk_entry_t *e = cmap_vk_find(&vikings, einar);
e->value += 5; // update
- cmap_vk_insert(&vikings, einar, 0).item->value += 5; // again
+ cmap_vk_emplace(&vikings, einar, 0).item->value += 5; // again
c_foreach (k, cmap_vk, vikings) {
printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value);
diff --git a/examples/birthday.c b/examples/birthday.c
index 5f5174d6..bf807e67 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_insert(&m, k, 0).item->value;
+ int v = ++cmap_ic_emplace(&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_insert(&map, crand_uniform_i32(&dist), 0).item->value;
+ ++cmap_x_emplace(&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 dd3a61ac..d2da77d9 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_insert(&mhist, index, 0).item->value += 1;
+ cmap_i_emplace(&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 fdc6d84c..194b92da 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_insert(&hash, a[i] % k, 0).item->value++;
+ cmap_ii_emplace(&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_insert(&hash, second, 0).item;
+ *hs = cmap_ii_emplace(&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 01b5c367..b65f097d 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -27,19 +27,19 @@ int main()
{"The Adventures of Sherlock Holmes", "Eye lyked it alot."},
));
/*
- cmap_str_insert(&book_reviews,
+ cmap_str_emplace(&book_reviews,
"Adventures of Huckleberry Finn",
"My favorite book."
);
- cmap_str_insert(&book_reviews,
+ cmap_str_emplace(&book_reviews,
"Grimms' Fairy Tales",
"Masterpiece."
);
- cmap_str_insert(&book_reviews,
+ cmap_str_emplace(&book_reviews,
"Pride and Prejudice",
"Very enjoyable."
);
- cmap_str_insert(&book_reviews,
+ cmap_str_emplace(&book_reviews,
"The Adventures of Sherlock Holmes",
"Eye lyked it alot."
);
diff --git a/examples/geek3.c b/examples/geek3.c
index 29614fc7..be3c8c10 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -15,10 +15,10 @@ int main ()
// ...
cmap_si_put(&mymap, "Mars", 3396);
- 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;
+ 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;
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 55f35bdd..ebb2e0e1 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -71,10 +71,10 @@ int main(void) {
{"Spain", 10},
{"France", 10},
));
- 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;
+ 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;
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 e1e78bba..f717a4bc 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_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_put(&cmap_cfg_emplace(&config, "user", init).item->value, "name", "Joe");
+ cmap_str_put(&cmap_cfg_emplace(&config, "user", init).item->value, "groups", "proj1,proj3");
+ cmap_str_put(&cmap_cfg_emplace(&config, "group", init).item->value, "proj1", "Energy");
+ cmap_str_put(&cmap_cfg_emplace(&config, "group", init).item->value, "proj2", "Windy");
+ cmap_str_put(&cmap_cfg_emplace(&config, "group", init).item->value, "proj3", "Oil");
+ cmap_str_put(&cmap_cfg_emplace(&config, "admin", init).item->value, "employees", "2302");
- cmap_str_put(&cmap_cfg_insert(&config, "group", init).item->value, "proj2", "Wind"); // Update
+ cmap_str_put(&cmap_cfg_emplace(&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 af637b8d..9e0fc0cc 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_insert(&word_map, w.item->str, 0).item->value += 1;
+ cmap_si_emplace(&word_map, w.item->str, 0).item->value += 1;
c_foreach (pair, cmap_si, word_map) {
printf("%d occurrences of word '%s'\n",