diff options
| author | Tyge Løvset <[email protected]> | 2021-02-21 19:44:29 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-02-21 19:44:29 +0100 |
| commit | 9ad1de563150b5819a17ceb07e5bb1a83f39f2b4 (patch) | |
| tree | 6b1e6fbf4dab50917b85642663c4a496199db1c6 /examples | |
| parent | c609469b3eac08cc369f30a54cc737a3d9cadc3b (diff) | |
| download | STC-modified-9ad1de563150b5819a17ceb07e5bb1a83f39f2b4.tar.gz STC-modified-9ad1de563150b5819a17ceb07e5bb1a83f39f2b4.zip | |
Renamed emplace_put() to emplace_or_assign(). May add put() as alias to insert_or_assign().
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 4 | ||||
| -rw-r--r-- | examples/csmap_v1.h | 2 | ||||
| -rw-r--r-- | examples/demos.c | 6 | ||||
| -rw-r--r-- | examples/inits.c | 10 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/mapmap.c | 2 | ||||
| -rw-r--r-- | examples/phonebook.c | 2 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/stc_astar.c | 4 |
9 files changed, 17 insertions, 17 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 01efc10c..391230f6 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -42,12 +42,12 @@ using_cmap_keyarg(vk, Viking, int, vikingraw_equals, vikingraw_hash, int main() { cmap_vk vikings = cmap_vk_init(); - c_emplace_n(&vikings, cmap_vk, { + c_emplace_items(&vikings, cmap_vk, { { {"Einar", "Norway"}, 20}, { {"Olaf", "Denmark"}, 24}, { {"Harald", "Iceland"}, 12}, }); - cmap_vk_emplace_put(&vikings, (VikingRaw){"Bjorn", "Sweden"}, 10); + cmap_vk_emplace_or_assign(&vikings, (VikingRaw){"Bjorn", "Sweden"}, 10); VikingRaw lookup = {"Einar", "Norway"}; diff --git a/examples/csmap_v1.h b/examples/csmap_v1.h index 4e785a2b..11602f83 100644 --- a/examples/csmap_v1.h +++ b/examples/csmap_v1.h @@ -231,7 +231,7 @@ int main(void) { return res; \
} \
STC_INLINE C##_##X##_result_t \
- C##_##X##_emplace_put(C##_##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
+ C##_##X##_emplace_or_assign(C##_##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
C##_##X##_result_t res = C##_##X##_insert_entry_(self, rkey); \
if (res.second) *KEY_REF_##C(res.first) = keyFromRaw(rkey); \
MAP_ONLY_##C( else mappedDel(&res.first->second); \
diff --git a/examples/demos.c b/examples/demos.c index 828a2c26..f60355e2 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -136,9 +136,9 @@ void mapdemo2() {
printf("\nMAPDEMO2\n");
cmap_si nums = cmap_si_init();
- cmap_si_emplace_put(&nums, "Hello", 64);
- cmap_si_emplace_put(&nums, "Groovy", 121);
- cmap_si_emplace_put(&nums, "Groovy", 200); // overwrite previous
+ 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))
diff --git a/examples/inits.c b/examples/inits.c index fd5fdbd3..bf209e88 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -24,7 +24,7 @@ int main(void) // CVEC FLOAT / PRIORITY QUEUE
cvec_f floats = cvec_f_init();
- c_emplace_n(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
+ c_emplace_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
c_foreach (i, cvec_f, floats) printf("%.1f ", *i.ref);
puts("");
@@ -32,7 +32,7 @@ int main(void) // CVEC PRIORITY QUEUE
cpque_f_make_heap(&floats);
- c_emplace_n(&floats, cpque_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
+ c_emplace_items(&floats, cpque_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
// sorted:
while (! cpque_f_empty(floats)) {
@@ -58,7 +58,7 @@ int main(void) // CMAP CNT
cmap_cnt countries = cmap_cnt_init();
- c_emplace_n(&countries, cmap_cnt, {
+ c_emplace_items(&countries, cmap_cnt, {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
@@ -81,7 +81,7 @@ int main(void) // CVEC PAIR
cvec_ip pairs1 = cvec_ip_init();
- c_emplace_n(&pairs1, cvec_ip, {
+ c_emplace_items(&pairs1, cvec_ip, {
{5, 6},
{3, 4},
{1, 2},
@@ -97,7 +97,7 @@ int main(void) // CLIST PAIR
clist_ip pairs2 = clist_ip_init();
- c_emplace_n(&pairs2, clist_ip, {
+ c_emplace_items(&pairs2, clist_ip, {
{5, 6},
{3, 4},
{1, 2},
diff --git a/examples/list.c b/examples/list.c index 47b17f2c..7ac49e19 100644 --- a/examples/list.c +++ b/examples/list.c @@ -33,7 +33,7 @@ int main() { puts("");
clist_fx_clear(&list);
- c_emplace_n(&list, clist_fx, {10, 20, 30, 40, 30, 50});
+ c_emplace_items(&list, clist_fx, {10, 20, 30, 40, 30, 50});
c_foreach (i, clist_fx, list) printf(" %g", *i.ref);
puts("");
diff --git a/examples/mapmap.c b/examples/mapmap.c index c55104c9..5a5996f6 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -16,7 +16,7 @@ int main(void) { cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).first->second, "proj3", "Oil");
cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("admin"), init).first->second, "employees", "2302");
- cmap_str_emplace_put(&cmap_cfg_insert(&config, cstr_from("group"), init).first->second, "proj2", "Wind"); // Update
+ cmap_str_emplace_or_assign(&cmap_cfg_insert(&config, cstr_from("group"), init).first->second, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
c_foreach (j, cmap_str, i.ref->second)
diff --git a/examples/phonebook.c b/examples/phonebook.c index 34364bcb..6b2ec687 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -67,7 +67,7 @@ int main(int argc, char **argv) printf("\nPhone book after erasing Tariq and Elliott:\n");
print_phone_book(phone_book);
- cmap_str_emplace_put(&phone_book, "Zak Byers", "(555) 396-188");
+ cmap_str_emplace_or_assign(&phone_book, "Zak Byers", "(555) 396-188");
printf("\nPhone book after update phone of Zak Byers:\n");
print_phone_book(phone_book);
diff --git a/examples/priority.c b/examples/priority.c index 4955a6aa..10e2f32a 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -20,7 +20,7 @@ int main() { cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
- c_emplace_n(&heap, cpque_i, {-231, -32, -873, -4, -343});
+ c_emplace_items(&heap, cpque_i, {-231, -32, -873, -4, -343});
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
diff --git a/examples/stc_astar.c b/examples/stc_astar.c index e7bb86e5..cdf1ff3c 100644 --- a/examples/stc_astar.c +++ b/examples/stc_astar.c @@ -106,10 +106,10 @@ astar(cstr maze, int width) csmap_mc_value_t* cost = csmap_mc_find(&cost_so_far, next).ref;
if (!cost || new_cost < cost->second)
{
- csmap_mc_emplace_put(&cost_so_far, next, new_cost); // update (put)
+ csmap_mc_emplace_or_assign(&cost_so_far, next, new_cost); // update (put)
next.priorty = new_cost + abs(goal.x - next.x) + abs(goal.y - next.y);
cpque_mp_push(&frontier, next);
- csmap_ms_emplace_put(&came_from, next, current);
+ csmap_ms_emplace_or_assign(&came_from, next, current);
}
}
}
|
