diff options
| author | Tyge Løvset <[email protected]> | 2021-03-11 11:29:57 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-03-11 11:29:57 +0100 |
| commit | c077e4b93a8d20c20b2626e2616d116be64247da (patch) | |
| tree | ad64f2bf54877fe2d47c54f0dbb7212277c87a28 /examples | |
| parent | 87ae20d6192380d2da50d439b88f89b6ff64a433 (diff) | |
| download | STC-modified-c077e4b93a8d20c20b2626e2616d116be64247da.tar.gz STC-modified-c077e4b93a8d20c20b2626e2616d116be64247da.zip | |
Renamed public *_result_t struct member names in maps/sets for consistency with iterators.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 4 | ||||
| -rw-r--r-- | examples/csmap_v1.h | 30 | ||||
| -rw-r--r-- | examples/ex_gauss1.c | 2 | ||||
| -rw-r--r-- | examples/ex_gauss2.c | 2 | ||||
| -rw-r--r-- | examples/inits.c | 8 | ||||
| -rw-r--r-- | examples/mapmap.c | 14 | ||||
| -rw-r--r-- | examples/words.c | 2 |
8 files changed, 32 insertions, 32 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index f2f2e756..33ceebbe 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -53,7 +53,7 @@ int main() VikingRaw einar = {"Einar", "Norway"}; cmap_vk_value_t *e = cmap_vk_find(&vikings, einar).ref; e->second += 3; // add 3 hp points to Einar - cmap_vk_emplace(&vikings, einar, 0).first->second += 5; // add 5 more to Einar + cmap_vk_emplace(&vikings, einar, 0).ref->second += 5; // add 5 more to Einar c_foreach (k, cmap_vk, vikings) { printf("%s of %s has %d hp\n", k.ref->first.name.str, k.ref->first.country.str, k.ref->second); diff --git a/examples/birthday.c b/examples/birthday.c index 45786fa9..5c5e0426 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).first->second;
+ int v = ++cmap_ic_emplace(&m, k, 0).ref->second;
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).first->second;
+ ++cmap_x_emplace(&map, k & 0xf, 0).ref->second;
}
uint64_t sum = 0;
diff --git a/examples/csmap_v1.h b/examples/csmap_v1.h index 861eeb5c..ec63c021 100644 --- a/examples/csmap_v1.h +++ b/examples/csmap_v1.h @@ -163,8 +163,8 @@ int main(void) { C##X##_rawvalue_t; \
\
typedef struct { \
- C##X##_value_t *first; \
- bool second; \
+ C##X##_value_t *ref; \
+ bool inserted; \
} C##X##_result_t; \
\
STC_API C##X \
@@ -224,9 +224,9 @@ int main(void) { STC_INLINE C##X##_result_t \
C##X##_emplace(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(res.first->second = mappedFromRaw(rmapped);) \
+ if (res.inserted) { \
+ *KEY_REF_##C(res.ref) = keyFromRaw(rkey); \
+ MAP_ONLY_##C(res.ref->second = mappedFromRaw(rmapped);) \
} \
return res; \
} \
@@ -239,8 +239,8 @@ int main(void) { STC_INLINE C##X##_result_t \
C##X##_insert(C##X* self, Key key MAP_ONLY_##C(, Mapped mapped)) { \
C##X##_result_t res = C##X##_insert_entry_(self, keyToRaw(&key)); \
- if (res.second) {*KEY_REF_##C(res.first) = key; MAP_ONLY_##C( res.first->second = mapped; )} \
- else {keyDel(&key); MAP_ONLY_##C( mappedDel(&mapped); )} \
+ if (res.inserted) {*KEY_REF_##C(res.ref) = key; MAP_ONLY_##C( res.ref->second = mapped; )} \
+ else {keyDel(&key); MAP_ONLY_##C( mappedDel(&mapped); )} \
return res; \
} \
\
@@ -248,9 +248,9 @@ int main(void) { STC_INLINE C##X##_result_t \
C##X##_insert_or_assign(C##X* self, Key key, Mapped mapped) { \
C##X##_result_t res = C##X##_insert_entry_(self, keyToRaw(&key)); \
- if (res.second) res.first->first = key; \
- else {keyDel(&key); mappedDel(&res.first->second);} \
- res.first->second = mapped; return res; \
+ if (res.inserted) res.ref->first = key; \
+ else {keyDel(&key); mappedDel(&res.ref->second);} \
+ res.ref->second = mapped; return res; \
} \
STC_INLINE C##X##_result_t \
C##X##_put(C##X* self, Key k, Mapped m) { \
@@ -259,9 +259,9 @@ int main(void) { STC_INLINE C##X##_result_t \
C##X##_emplace_or_assign(C##X* self, RawKey rkey, RawMapped rmapped) { \
C##X##_result_t res = C##X##_insert_entry_(self, rkey); \
- if (res.second) res.first->first = keyFromRaw(rkey); \
- else mappedDel(&res.first->second); \
- res.first->second = mappedFromRaw(rmapped); return res; \
+ if (res.inserted) res.ref->first = keyFromRaw(rkey); \
+ else mappedDel(&res.ref->second); \
+ res.ref->second = mappedFromRaw(rmapped); return res; \
} \
STC_INLINE C##X##_mapped_t* \
C##X##_at(const C##X* self, RawKey rkey) { \
@@ -296,7 +296,7 @@ int main(void) { } \
STC_INLINE C##X##_mapped_t* \
C##X##_itval(C##X##_iter_t it) {return SET_ONLY_##C( it.ref ) \
- MAP_ONLY_##C( &it.ref->second );} \
+ MAP_ONLY_##C( &it.ref->second );} \
\
STC_API C##X##_node_t* \
C##X##_erase_r_(C##X##_node_t *tn, const C##X##_rawkey_t* rkey, int *erased); \
@@ -406,7 +406,7 @@ int main(void) { C##X##_insert_entry_(C##X* self, RawKey rkey) { \
C##X##_result_t res = {NULL, false}; \
self->root = C##X##_insert_entry_i_(self->root, &rkey, &res); \
- self->size += res.second; \
+ self->size += res.inserted; \
return res; \
} \
\
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index 6536527d..99d17b23 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -31,7 +31,7 @@ int main() cmap_i mhist = cmap_i_init();
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
- ++ cmap_i_emplace(&mhist, index, 0).first->second;
+ cmap_i_emplace(&mhist, index, 0).ref->second += 1;
}
// Transfer map to vec and sort it by map keys.
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c index 616d7071..60195e7d 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -24,7 +24,7 @@ int main() csmap_i mhist = csmap_i_init();
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
- ++ csmap_i_emplace(&mhist, index, 0).first->second;
+ csmap_i_emplace(&mhist, index, 0).ref->second += 1;
}
// Print the gaussian bar chart
diff --git a/examples/inits.c b/examples/inits.c index 0c716fd1..23c7b551 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).first->second += 20;
- cmap_cnt_emplace(&countries, "Sweden", 0).first->second += 20;
- cmap_cnt_emplace(&countries, "Norway", 0).first->second += 20;
- cmap_cnt_emplace(&countries, "Finland", 0).first->second += 20;
+ cmap_cnt_emplace(&countries, "Greenland", 0).ref->second += 20;
+ cmap_cnt_emplace(&countries, "Sweden", 0).ref->second += 20;
+ cmap_cnt_emplace(&countries, "Norway", 0).ref->second += 20;
+ cmap_cnt_emplace(&countries, "Finland", 0).ref->second += 20;
c_foreach (i, cmap_cnt, countries)
printf("%s: %d\n", i.ref->first.str, i.ref->second);
diff --git a/examples/mapmap.c b/examples/mapmap.c index c775d870..e22ac80c 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -9,14 +9,14 @@ using_cmap_strkey(cfg, cmap_str, cmap_str_del, c_no_clone); int main(void) {
cmap_cfg config = cmap_cfg_init();
cmap_str init = cmap_str_init();
- cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("user"), init).first->second, "name", "Joe");
- cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("user"), init).first->second, "groups", "proj1,proj3");
- cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).first->second, "proj1", "Energy");
- cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).first->second, "proj2", "Windy");
- 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(&cmap_cfg_insert(&config, cstr_from("user"), init).ref->second, "name", "Joe");
+ cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("user"), init).ref->second, "groups", "proj1,proj3");
+ cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).ref->second, "proj1", "Energy");
+ cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).ref->second, "proj2", "Windy");
+ cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("group"), init).ref->second, "proj3", "Oil");
+ cmap_str_emplace(&cmap_cfg_insert(&config, cstr_from("admin"), init).ref->second, "employees", "2302");
- cmap_str_emplace_or_assign(&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).ref->second, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
c_foreach (j, cmap_str, i.ref->second)
diff --git a/examples/words.c b/examples/words.c index b3bd963f..4b8bd11b 100644 --- a/examples/words.c +++ b/examples/words.c @@ -28,7 +28,7 @@ int main1() cmap_si word_map = cmap_si_init(); c_foreach (w, cvec_str, words) - cmap_si_emplace(&word_map, w.ref->str, 0).first->second += 1; + cmap_si_emplace(&word_map, w.ref->str, 0).ref->second += 1; c_foreach (i, cmap_si, word_map) { printf("%d occurrences of word '%s'\n", i.ref->second, i.ref->first.str); |
