From c077e4b93a8d20c20b2626e2616d116be64247da Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 11 Mar 2021 11:29:57 +0100 Subject: Renamed public *_result_t struct member names in maps/sets for consistency with iterators. --- benchmarks/shootout1_cmap.cpp | 2 +- benchmarks/shootout2_cmap.cpp | 4 ++-- benchmarks/shootout3_csmap.cpp | 2 +- docs/cmap_api.md | 5 +++-- docs/crandom_api.md | 9 +++++---- docs/csmap_api.md | 22 +++++++++++----------- examples/advanced.c | 2 +- examples/birthday.c | 4 ++-- examples/csmap_v1.h | 30 +++++++++++++++--------------- examples/ex_gauss1.c | 2 +- examples/ex_gauss2.c | 2 +- examples/inits.c | 8 ++++---- examples/mapmap.c | 14 +++++++------- examples/words.c | 2 +- stc/cmap.h | 30 +++++++++++++++--------------- stc/csmap.h | 32 ++++++++++++++++---------------- 16 files changed, 86 insertions(+), 84 deletions(-) diff --git a/benchmarks/shootout1_cmap.cpp b/benchmarks/shootout1_cmap.cpp index f88d5ad6..7f75a242 100644 --- a/benchmarks/shootout1_cmap.cpp +++ b/benchmarks/shootout1_cmap.cpp @@ -145,7 +145,7 @@ static void ins_and_access_cmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (N1) - result += ++cmap_i_emplace(&map, stc64_random() & mask, 0).first->second; + result += ++cmap_i_emplace(&map, stc64_random() & mask, 0).ref->second; s.set_result(result); cmap_i_del(&map); } diff --git a/benchmarks/shootout2_cmap.cpp b/benchmarks/shootout2_cmap.cpp index 33d9dad8..cea7b6ec 100644 --- a/benchmarks/shootout2_cmap.cpp +++ b/benchmarks/shootout2_cmap.cpp @@ -32,8 +32,8 @@ stc64_t rng; #define CMAP_SETUP(X, Key, Value) cmap_##X map = cmap_##X##_init() \ ; cmap_##X##_set_load_factors(&map, 0.0, max_load_factor) -#define CMAP_PUT(X, key, val) cmap_##X##_emplace_or_assign(&map, key, val).first->second -#define CMAP_EMPLACE(X, key, val) cmap_##X##_emplace(&map, key, val).first->second +#define CMAP_PUT(X, key, val) cmap_##X##_emplace_or_assign(&map, key, val).ref->second +#define CMAP_EMPLACE(X, key, val) cmap_##X##_emplace(&map, key, val).ref->second #define CMAP_ERASE(X, key) cmap_##X##_erase(&map, key) #define CMAP_FIND(X, key) (cmap_##X##_find(map, key) != NULL) #define CMAP_FOR(X, i) c_foreach (i, cmap_##X, map) diff --git a/benchmarks/shootout3_csmap.cpp b/benchmarks/shootout3_csmap.cpp index d7072445..de14d4ba 100644 --- a/benchmarks/shootout3_csmap.cpp +++ b/benchmarks/shootout3_csmap.cpp @@ -169,7 +169,7 @@ static void ins_and_access_csmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (s.iterations()) { - result += ++csmap_i_emplace(&map, stc64_random() & mask, 0).first->second; + result += ++csmap_i_emplace(&map, stc64_random() & mask, 0).ref->second; csmap_i_iter_t it = csmap_i_find(&map, stc64_random() & mask); if (it.ref) csmap_i_erase(&map, it.ref->first); } diff --git a/docs/cmap_api.md b/docs/cmap_api.md index ce5b310d..e4aa886f 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -73,6 +73,7 @@ cmap_X_mapped_t* cmap_X_at(const cmap_X* self, RawKey rkey); size_t cmap_X_erase(cmap_X* self, RawKey rkey); cmap_X_iter_t cmap_X_erase_at(cmap_X* self, cmap_X_iter_t pos); +void cmap_X_erase_entry(cmap_X* self, cmap_X_value_t* entry); cmap_X_iter_t cmap_X_begin(const cmap_X* self); cmap_X_iter_t cmap_X_end(const cmap_X* self); @@ -104,7 +105,7 @@ void c_trivial_del(Type* val); // doe | `cmap_X_mapped_t` | `Mapped` | The mapped type | | `cmap_X_value_t` | `struct { Key first; Mapped second; }` | The value type | | `cmap_X_rawvalue_t` | `struct { RawKey first; RawMapped second; }` | RawKey + RawMapped type | -| `cmap_X_result_t` | `struct { cmap_X_value_t *first; bool second; }`| Result of insert/put/emplace | +| `cmap_X_result_t` | `struct { cmap_X_value_t *ref; bool inserted; }`| Result of insert/put/emplace | | `cmap_X_iter_t` | `struct { cmap_X_value_t *ref; ... }` | Iterator type | ## Constants and macros @@ -313,7 +314,7 @@ int main() cmap_vk_value_t *e = cmap_vk_find(&vikings, lookup).ref; e->second += 3; // add 3 hp points to Einar - cmap_vk_emplace(&vikings, lookup, 0).first->second += 5; // add 5 more to Einar + cmap_vk_emplace(&vikings, lookup, 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/docs/crandom_api.md b/docs/crandom_api.md index d67a1fb3..36d66c3c 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -10,10 +10,11 @@ See [random](https://en.cppreference.com/w/cpp/header/random) for similar c++ fu **stc64** is a novel, extremely fast PRNG by Tyge Løvset, suited for parallel usage. It features a Weyl-sequence as part of the state. In general testing, **stc64** is the fastest among *pcg64*, -*xoshiro256`**`*, *sfc64*, and *lehmer64*. On some platforms, *wyrand64* is faster, but it has only -128-bit state with no minimum period length guarantee. +*xoshiro256`**`*, *sfc64*, and *lehmer64*. *wyrand* is faster on platforms with fast 128-bit +multiplication, and has 2^64 period length (https://github.com/lemire/SwiftWyhash/issues/10). +However, it is not suited for massive parallel usage due to its limited total minimal period length. -**stc64** does not require fast multiplication or 128-bit integer operations. It has 256 bit state, +**stc64** does not require multiplication or 128-bit integer operations. It has 256 bit state, but updates only 192 bit per generated number. There is no *jump function*, but each odd number Weyl-increment (state[3]) starts a new @@ -90,7 +91,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; } // Print the gaussian bar chart diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 8c3a31b5..7f7c5e96 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -79,17 +79,17 @@ csmap_X_value_t csmap_X_value_clone(csmap_X_value_t val); ``` ## Types -| Type name | Type definition | Used to represent... | -|:----------------------|:------------------------------------------------ |:-----------------------------| -| `csmap_X` | `struct { ... }` | The csmap type | -| `csmap_X_rawkey_t` | `RawKey` | The raw key type | -| `csmap_X_rawmapped_t` | `RawMapped` | The raw mapped type | -| `csmap_X_key_t` | `Key` | The key type | -| `csmap_X_mapped_t` | `Mapped` | The mapped type | -| `csmap_X_value_t` | `struct { Key first; Mapped second; }` | The value type | -| `csmap_X_rawvalue_t` | `struct { RawKey first; RawMapped second; }` | RawKey + RawVal type | -| `csmap_X_result_t` | `struct { csmap_X_value_t first; bool second; }` | Result of insert/put/emplace | -| `csmap_X_iter_t` | `struct { csmap_X_value_t *ref; ... }` | Iterator type | +| Type name | Type definition | Used to represent... | +|:----------------------|:--------------------------------------------------|:-----------------------------| +| `csmap_X` | `struct { ... }` | The csmap type | +| `csmap_X_rawkey_t` | `RawKey` | The raw key type | +| `csmap_X_rawmapped_t` | `RawMapped` | The raw mapped type | +| `csmap_X_key_t` | `Key` | The key type | +| `csmap_X_mapped_t` | `Mapped` | The mapped type | +| `csmap_X_value_t` | `struct { Key first; Mapped second; }` | The value type | +| `csmap_X_rawvalue_t` | `struct { RawKey first; RawMapped second; }` | RawKey + RawVal type | +| `csmap_X_result_t` | `struct { csmap_X_value_t *ref; bool inserted; }` | Result of insert/put/emplace | +| `csmap_X_iter_t` | `struct { csmap_X_value_t *ref; ... }` | Iterator type | ## Examples ```c 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); diff --git a/stc/cmap.h b/stc/cmap.h index 78413064..485bfe42 100644 --- a/stc/cmap.h +++ b/stc/cmap.h @@ -184,8 +184,8 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; C##X##_rawvalue_t; \ \ typedef struct { \ - C##X##_value_t *first; \ - bool second; /* inserted */ \ + C##X##_value_t *ref; \ + bool inserted; \ } C##X##_result_t; \ \ typedef struct { \ @@ -255,9 +255,9 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; 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; \ } \ @@ -270,8 +270,8 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; 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; \ } \ \ @@ -279,9 +279,9 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; 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) { /* shorter, like operator[] */ \ @@ -290,9 +290,9 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; 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) { \ @@ -317,7 +317,7 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; } \ 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 void \ C##X##_erase_entry(C##X* self, C##X##_value_t* val); \ @@ -417,7 +417,7 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um C##X##_reserve_expand_(self); \ chash_bucket_t b = C##X##_bucket_(self, &rkey); \ C##X##_result_t res = {&self->table[b.idx], !self->_hashx[b.idx]}; \ - if (res.second) { \ + if (res.inserted) { \ self->_hashx[b.idx] = b.hx; \ ++self->size; \ } \ diff --git a/stc/csmap.h b/stc/csmap.h index a58fdc18..e2cc6fcf 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -169,8 +169,8 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; C##X##_rawvalue_t; \ \ typedef struct { \ - C##X##_value_t *first; \ - bool second; /* inserted */ \ + C##X##_value_t *ref; \ + bool inserted; \ } C##X##_result_t; \ \ typedef struct C##X##_node { \ @@ -247,9 +247,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; 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; \ } \ @@ -262,8 +262,8 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; 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; \ } \ \ @@ -271,9 +271,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; 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) { \ @@ -282,9 +282,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; 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) { \ @@ -439,12 +439,12 @@ static struct csmap_rep _smap_inits = {0, 0, 0, 0}; while (it) { \ up[top++] = it; \ C##X##_rawkey_t raw = keyToRaw(KEY_REF_##C(&d[it].value)); \ - if ((c = keyCompareRaw(&raw, rkey)) == 0) {res->first = &d[it].value; return tn;} \ + if ((c = keyCompareRaw(&raw, rkey)) == 0) {res->ref = &d[it].value; return tn;} \ dir = (c == -1); \ it = d[it].link[dir]; \ } \ it = C##X##_node_new_(self, 1); d = self->nodes; \ - res->first = &d[it].value, res->second = true; \ + res->ref = &d[it].value, res->inserted = true; \ if (top == 0) return it; \ d[up[top - 1]].link[dir] = it; \ while (top--) { \ @@ -461,7 +461,7 @@ static struct csmap_rep _smap_inits = {0, 0, 0, 0}; C##X##_result_t res = {NULL, false}; \ C##X##_size_t tn = C##X##_insert_entry_i_(self, (C##X##_size_t) _csmap_rep(self)->root, &rkey, &res); \ _csmap_rep(self)->root = tn; \ - _csmap_rep(self)->size += res.second; \ + _csmap_rep(self)->size += res.inserted; \ return res; \ } \ \ -- cgit v1.2.3