diff options
| author | tylo <[email protected]> | 2020-09-07 10:15:41 +0200 |
|---|---|---|
| committer | tylo <[email protected]> | 2020-09-07 10:17:15 +0200 |
| commit | 2dbbf289ae169bbe633632fa119557fab36fdbb4 (patch) | |
| tree | 90c0cbe1f989290f26f5671e34cb56ec6b93c951 | |
| parent | 5b78847871217562dcddbb0bd34076a892eb49e1 (diff) | |
| download | STC-modified-2dbbf289ae169bbe633632fa119557fab36fdbb4.tar.gz STC-modified-2dbbf289ae169bbe633632fa119557fab36fdbb4.zip | |
Added back cmap insert()
| -rw-r--r-- | examples/birthday.c | 4 | ||||
| -rw-r--r-- | examples/ex_gaussian.c | 2 | ||||
| -rw-r--r-- | examples/geek1.c | 4 | ||||
| -rw-r--r-- | examples/geek2.c | 3 | ||||
| -rw-r--r-- | examples/geek3.c | 8 | ||||
| -rw-r--r-- | examples/inits.c | 8 | ||||
| -rw-r--r-- | examples/mapmap.c | 14 | ||||
| -rw-r--r-- | examples/words.c | 2 | ||||
| -rw-r--r-- | stc/cmap.h | 9 | ||||
| -rw-r--r-- | stc/crandom.h | 4 |
10 files changed, 29 insertions, 29 deletions
diff --git a/examples/birthday.c b/examples/birthday.c index bf807e67..5f5174d6 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_emplace(&m, k, 0).item->value;
+ int v = ++cmap_ic_insert(&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_emplace(&map, crand_uniform_i32(&dist), 0).item->value;
+ ++cmap_x_insert(&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 d2da77d9..dd3a61ac 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_emplace(&mhist, index, 0).item->value += 1;
+ cmap_i_insert(&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 194b92da..fdc6d84c 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_emplace(&hash, a[i] % k, 0).item->value++;
+ cmap_ii_insert(&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_emplace(&hash, second, 0).item;
+ *hs = cmap_ii_insert(&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 0e8b384a..01b5c367 100644 --- a/examples/geek2.c +++ b/examples/geek2.c @@ -16,7 +16,8 @@ int main() cset_str_put(&set, "You");
cset_str_put(&set, "Tube");
c_foreach (i, cset_str, set)
- printf("%s ", i.item->key.str); puts("");
+ printf("%s ", i.item->key.str);
+ puts("");
// Review some books.
c_push(&book_reviews, cmap_str, c_items(
diff --git a/examples/geek3.c b/examples/geek3.c index be3c8c10..29614fc7 100644 --- a/examples/geek3.c +++ b/examples/geek3.c @@ -15,10 +15,10 @@ int main () // ...
cmap_si_put(&mymap, "Mars", 3396);
- 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;
+ 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;
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 16882e7a..fa9de214 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).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;
+ 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;
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 6929dc69..e1e78bba 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_insert_or_assign(&cmap_cfg_emplace(&config, "user", init).item->value, "name", "Joe");
- cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "user", init).item->value, "groups", "proj1,proj3");
- cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj1", "Energy");
- cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj2", "Windy");
- cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj3", "Oil");
- cmap_str_insert_or_assign(&cmap_cfg_emplace(&config, "admin", init).item->value, "employees", "2302");
+ 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_insert_or_assign(&cmap_cfg_emplace(&config, "group", init).item->value, "proj2", "Wind"); // Update
+ cmap_str_put(&cmap_cfg_insert(&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 92f98c85..af637b8d 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_emplace(&word_map, w.item->str, 0).item->value; + cmap_si_insert(&word_map, w.item->str, 0).item->value += 1; c_foreach (pair, cmap_si, word_map) { printf("%d occurrences of word '%s'\n", @@ -218,17 +218,16 @@ ctype##_##X##_contains(const ctype##_##X* self, ctype##_##X##_rawkey_t rawKey); STC_API ctype##_##X##_result_t \
ctype##_##X##_insert_key_(ctype##_##X* self, ctype##_##X##_rawkey_t rawKey); \
\
-CSET_ONLY_##ctype( STC_INLINE ctype##_##X##_result_t \
-ctype##_##X##_insert(ctype##_##X* self, ctype##_##X##_rawkey_t rawKey) { \
- return ctype##_##X##_insert_key_(self, rawKey); \
-}) \
STC_INLINE ctype##_##X##_result_t \
ctype##_##X##_emplace(ctype##_##X* self, CMAP_ARGS_##ctype(ctype##_##X##_rawkey_t rawKey, RawValue rawValue)) { \
ctype##_##X##_result_t res = ctype##_##X##_insert_key_(self, rawKey); \
CMAP_ONLY_##ctype( if (res.inserted) res.item->value = valueFromRaw(rawValue); ) \
return res; \
} \
- \
+STC_INLINE ctype##_##X##_result_t \
+ctype##_##X##_insert(ctype##_##X* self, CMAP_ARGS_##ctype(ctype##_##X##_rawkey_t rawKey, RawValue rawValue)) { \
+ return ctype##_##X##_emplace(self, CMAP_ARGS_##ctype(rawKey, rawValue)); \
+} \
CMAP_ONLY_##ctype( \
STC_INLINE ctype##_##X##_result_t \
ctype##_##X##_insert_or_assign(ctype##_##X* self, ctype##_##X##_rawkey_t rawKey, RawValue rawValue) { \
diff --git a/stc/crandom.h b/stc/crandom.h index d1a85395..07457332 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -133,7 +133,7 @@ STC_API double crand_normal_f64(crand_normal_f64_t* dist); #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
STC_API crand_rng32_t crand_rng32_with_seq(uint64_t seed, uint64_t seq) {
- crand_rng32_t rng = {0u, (seq << 1u) | 1u}; /* inc must be odd */
+ crand_rng32_t rng = {{0u, (seq << 1u) | 1u}}; /* inc must be odd */
crand_i32(&rng);
rng.state[0] += seed;
crand_i32(&rng);
@@ -155,7 +155,7 @@ STC_API uint32_t crand_i32(crand_rng32_t* rng) { /* Guarantees 2^63 unique threads with minimum 2^64 period length ~ 2^160 average period. */
/* Tested with PractRand to 8 TB output: no issues */
STC_API crand_rng64_t crand_rng64_with_seq(uint64_t seed, uint64_t seq) {
- crand_rng64_t rng = {seed, seed, seed, (seq << 1u) | 1u}; /* increment must be odd */
+ crand_rng64_t rng = {{seed, seed, seed, (seq << 1u) | 1u}}; /* increment must be odd */
for (int i = 0; i < 12; ++i) crand_i64(&rng);
return rng;
}
|
