summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-08-29 23:31:21 +0200
committerTyge Løvset <[email protected]>2020-08-29 23:31:21 +0200
commitc15b39eed1f7041b1fb84a72da4e4e0fae1318a8 (patch)
tree771744253a9c1739b3cb90af254d88030a1dbc6c
parent8efecc5d6b8d4dcd6a7bdf9540a11355b4631782 (diff)
downloadSTC-modified-c15b39eed1f7041b1fb84a72da4e4e0fae1318a8.tar.gz
STC-modified-c15b39eed1f7041b1fb84a72da4e4e0fae1318a8.zip
Cleanup and fix mapmap example.
-rw-r--r--examples/mapmap.c29
-rw-r--r--stc/crandom.h4
2 files changed, 13 insertions, 20 deletions
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 1f2bd4f5..d0d8c8fa 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -3,31 +3,24 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-static void my_str_destr(cstr_t* x) {
- printf("destroy: %s\n", x->str);
- cstr_destroy(x);
-}
-
-declare_cmap_strkey(ss, cstr_t, my_str_destr);
-declare_cmap_strkey(cfg, cmap_ss, cmap_ss_destroy);
+declare_cmap_str();
+declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
cmap_cfg config = cmap_init;
- cmap_ss init = cmap_init;
- cmap_ss_put(&cmap_cfg_insert(&config, "user", init)->value, "name", cstr_make("Joe"));
- cmap_ss_put(&cmap_cfg_insert(&config, "user", init)->value, "groups", cstr_make("proj1,proj3"));
- cmap_ss_put(&cmap_cfg_insert(&config, "group", init)->value, "proj1", cstr_make("Energy"));
- cmap_ss_put(&cmap_cfg_insert(&config, "group", init)->value, "proj2", cstr_make("Windy"));
- cmap_ss_put(&cmap_cfg_insert(&config, "group", init)->value, "proj3", cstr_make("Oil"));
- cmap_ss_put(&cmap_cfg_insert(&config, "admin", init)->value, "employees", cstr_make("2302"));
+ cmap_str init = cmap_init;
+ cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "name", "Joe");
+ cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "groups", "proj1,proj3");
+ cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj1", "Energy");
+ cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj2", "Windy");
+ cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj3", "Oil");
+ cmap_str_put(&cmap_cfg_insert(&config, "admin", init)->value, "employees", "2302");
- cmap_ss_put(&cmap_cfg_insert(&config, "group", init)->value, "proj2", cstr_make("Wind")); // Update
- puts("");
+ cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
- c_foreach (j, cmap_ss, i.item->value)
+ c_foreach (j, cmap_str, i.item->value)
printf("%s: %s - %s (%u)\n", i.item->key.str, j.item->key.str, j.item->value.str, i.item->value.bucket_count);
- puts("");
cmap_cfg_destroy(&config);
} \ No newline at end of file
diff --git a/stc/crandom.h b/stc/crandom.h
index 5821b4e7..d1a85395 100644
--- a/stc/crandom.h
+++ b/stc/crandom.h
@@ -59,7 +59,7 @@ STC_INLINE float crand_f32(crand_rng32_t* rng) {
/* int random number generator in range [low, high] */
STC_INLINE crand_uniform_i32_t crand_uniform_i32_init(crand_rng32_t rng, int32_t low, int32_t high) {
- crand_uniform_i32_t dist = {rng, low, high - low + 1}; return dist;
+ crand_uniform_i32_t dist = {rng, low, (uint32_t) (high - low + 1)}; return dist;
}
STC_INLINE int32_t crand_uniform_i32(crand_uniform_i32_t* dist) {
return dist->offset + (int32_t) (((uint64_t) crand_i32(&dist->rng) * dist->range) >> 32);
@@ -100,7 +100,7 @@ STC_INLINE double crand_f64(crand_rng64_t* rng) {
/* int random number generator in range [low, high] */
STC_INLINE crand_uniform_i64_t crand_uniform_i64_init(crand_rng64_t rng, int64_t low, int64_t high) {
- crand_uniform_i64_t dist = {rng, low, high - low + 1}; return dist;
+ crand_uniform_i64_t dist = {rng, low, (uint64_t) (high - low + 1)}; return dist;
}
#if defined(_MSC_VER) && defined(_WIN64)