diff options
| author | Tyge Løvset <[email protected]> | 2020-08-29 23:31:21 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-08-29 23:31:21 +0200 |
| commit | c15b39eed1f7041b1fb84a72da4e4e0fae1318a8 (patch) | |
| tree | 771744253a9c1739b3cb90af254d88030a1dbc6c /examples/mapmap.c | |
| parent | 8efecc5d6b8d4dcd6a7bdf9540a11355b4631782 (diff) | |
| download | STC-modified-c15b39eed1f7041b1fb84a72da4e4e0fae1318a8.tar.gz STC-modified-c15b39eed1f7041b1fb84a72da4e4e0fae1318a8.zip | |
Cleanup and fix mapmap example.
Diffstat (limited to 'examples/mapmap.c')
| -rw-r--r-- | examples/mapmap.c | 29 |
1 files changed, 11 insertions, 18 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 |
