summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-30 18:48:23 +0200
committerTyge Løvset <[email protected]>2020-07-30 18:48:23 +0200
commita1c3ca1e5b34715cde8ea1809b688d5fef9ad99f (patch)
treeb3d074c00e1dd83ee75ab9d15718dc5b46ad2818 /examples
parentd749237b490e85b43ce4be093976b5f809964087 (diff)
downloadSTC-modified-a1c3ca1e5b34715cde8ea1809b688d5fef9ad99f.tar.gz
STC-modified-a1c3ca1e5b34715cde8ea1809b688d5fef9ad99f.zip
Small tweak.
Diffstat (limited to 'examples')
-rw-r--r--examples/inits.c5
-rw-r--r--examples/mapmap.c37
2 files changed, 27 insertions, 15 deletions
diff --git a/examples/inits.c b/examples/inits.c
index 0d3f8bd8..91973190 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -62,6 +62,11 @@ int main(void) {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
+ {"Belgium", 10},
+ {"Italy", 10},
+ {"Germany", 10},
+ {"Spain", 10},
+ {"France", 10},
));
cmap_cnt_insert(&countries, "Sweden", 0)->value += 20;
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 82f35cd3..14ccd9a9 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -1,26 +1,33 @@
#include <stdio.h>
#include <stc/cmap.h>
+#include <stc/cstr.h>
-static void test_destr(int* x) {
- printf("destroy int: %d\n", *x);
+static void my_str_destr(cstr_t* x) {
+ printf("destroy: %s\n", x->str);
+ cstr_destroy(x);
}
-declare_cmap(ii, int, int, test_destr);
-declare_cmap(im, int, cmap_ii, cmap_ii_destroy);
+declare_cmap_str(ss, cstr_t, my_str_destr);
+declare_cmap_str(cfg, cmap_ss, cmap_ss_destroy);
int main(void) {
- cmap_im m = cmap_init;
- cmap_ii init = cmap_init;
- cmap_ii_put(&cmap_im_insert(&m, 100, init)->value, 2000, 200);
- cmap_ii_put(&cmap_im_insert(&m, 100, init)->value, 2001, 201);
- cmap_ii_put(&cmap_im_insert(&m, 100, init)->value, 2000, 400); // update
- cmap_ii_put(&cmap_im_insert(&m, 110, init)->value, 2000, 500);
- cmap_ii_put(&cmap_im_insert(&m, 120, init)->value, 3000, 600);
+ 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"));
- c_foreach (i, cmap_im, m)
- c_foreach (j, cmap_ii, i.item->value)
- printf("%d: %d - %d\n", i.item->key, j.item->key, j.item->value);
+ cmap_ss_put(&cmap_cfg_insert(&config, "group", init)->value, "proj2", cstr_make("Wind")); // Update
+ puts("");
- cmap_im_destroy(&m);
+ c_foreach (i, cmap_cfg, config)
+ c_foreach (j, cmap_ss, 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