diff options
| author | Tyge Løvset <[email protected]> | 2021-04-17 08:02:39 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-04-17 08:02:39 +0200 |
| commit | 0dfe69fa5dd7d4d9dded93d35106537e1ea76243 (patch) | |
| tree | 3c94d8d4f6ef2aa6b9d5c19fc6da3e69521bf18b /examples | |
| parent | 23ad1fbb91ef3cdddec7e54f3bde79082c2b0e24 (diff) | |
| download | STC-modified-0dfe69fa5dd7d4d9dded93d35106537e1ea76243.tar.gz STC-modified-0dfe69fa5dd7d4d9dded93d35106537e1ea76243.zip | |
Changed c_emplace_items(&cont, ctype, {...}) macro with c_emplace(ctype, cont, {...}): consistent with c_init(ctype, cont, {...}).
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 6 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/read.c | 2 |
6 files changed, 9 insertions, 9 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 33ceebbe..795f3f63 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -42,7 +42,7 @@ using_cmap_keydef(vk, Viking, int, vikingraw_equals, vikingraw_hash, int main() { cmap_vk vikings = cmap_vk_init(); - c_emplace_items(&vikings, cmap_vk, { + c_emplace(cmap_vk, vikings, { { {"Einar", "Norway"}, 20}, { {"Olaf", "Denmark"}, 24}, { {"Harald", "Iceland"}, 12}, diff --git a/examples/birthday.c b/examples/birthday.c index 5c5e0426..b2fc834c 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -20,7 +20,7 @@ static void test_repeats(void) cmap_ic_reserve(&m, N);
c_forrange (i, N) {
uint64_t k = stc64_rand(&rng) & mask;
- int v = ++cmap_ic_emplace(&m, k, 0).ref->second;
+ int v = cmap_ic_emplace(&m, k, 0).ref->second += 1;
if (v > 1) printf("repeated value %llx (%d) at 2^%d\n", k, v, (int) log2(i));
}
}
@@ -38,7 +38,7 @@ void test_distribution(void) c_forrange (N) {
uint64_t k = stc64_rand(&rng);
- ++cmap_x_emplace(&map, k & 0xf, 0).ref->second;
+ cmap_x_emplace(&map, k & 0xf, 0).ref->second += 1;
}
uint64_t sum = 0;
diff --git a/examples/inits.c b/examples/inits.c index 26518e33..003acfa3 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_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
+ c_emplace(cvec_f, floats, {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_items(&floats, cpque_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
+ c_emplace(cpque_f, floats, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
puts("\npop and show high priorites first:");
while (! cpque_f_empty(floats)) {
@@ -58,7 +58,7 @@ int main(void) // CMAP CNT
cmap_cnt countries = cmap_cnt_init();
- c_emplace_items(&countries, cmap_cnt, {
+ c_emplace(cmap_cnt, countries, {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
diff --git a/examples/list.c b/examples/list.c index 2bc493b9..4b75468d 100644 --- a/examples/list.c +++ b/examples/list.c @@ -33,7 +33,7 @@ int main() { puts("");
clist_fx_clear(&list);
- c_emplace_items(&list, clist_fx, {10, 20, 30, 40, 30, 50});
+ c_emplace(clist_fx, list, {10, 20, 30, 40, 30, 50});
c_foreach (i, clist_fx, list) printf(" %g", *i.ref);
puts("");
diff --git a/examples/priority.c b/examples/priority.c index ed7db584..ec26cb15 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_items(&heap, cpque_i, {-231, -32, -873, -4, -343});
+ c_emplace(cpque_i, heap, {-231, -32, -873, -4, -343});
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
diff --git a/examples/read.c b/examples/read.c index b3ddcc00..2324d1df 100644 --- a/examples/read.c +++ b/examples/read.c @@ -6,7 +6,7 @@ using_cvec_str(); cvec_str read_file(const char* name) {
cvec_str vec = cvec_str_init();
- c_withfile (f, fopen(name, "r")) {
+ for (FILE* f = fopen(name, "r"); f; fclose(f), f=NULL) {
cstr line = cstr_init();
while (cstr_getline(&line, f))
cvec_str_emplace_back(&vec, line.str);
|
