From c15b39eed1f7041b1fb84a72da4e4e0fae1318a8 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sat, 29 Aug 2020 23:31:21 +0200 Subject: Cleanup and fix mapmap example. --- examples/mapmap.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'examples') 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 #include -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 -- cgit v1.2.3