37 printf(
"Id to Name Map Example:\n");
38 id_to_name map = id_to_name_new(stdalloc_get());
40 id_to_name_insert(&map, 23,
"hello");
41 id_to_name_insert(&map, 10,
"bob");
42 id_to_name_insert(&map, 42,
"meaning");
43 ASSERT(strcmp(*id_to_name_read(&map, 42),
"meaning") == 0);
47 char const** entry = id_to_name_write(&map, 23);
49 *entry =
"a different string!";
53 id_to_name_delete(&map);
89 printf(
"Report Map Example:\n");
90 report_map map = report_map_new(stdalloc_get());
92 struct report_id id1 = {.name = strdup(
"Report A"), .section = 1};
93 struct report_id id2 = {.name = strdup(
"Report B"), .section = 2};
95 report_map_insert(&map, id1,
96 (
struct report){.description = strdup(
"Description A"), .value = 100});
97 report_map_insert(&map, id2,
98 (
struct report){.description = strdup(
"Description B"), .value = 200});
100 assert(strcmp(report_map_read(&map, id1)->description,
"Description A") == 0);
103 report_map_iter_const iter = report_map_get_iter_const(&map);
104 report_map_kv_const
const* entry = NULL;
106 while ((entry = report_map_iter_const_next(&iter))) {
107 printf(
"Position: %zu Key: %s Section: %u Value: %d\n", pos, entry->key->name,
108 entry->key->section, entry->value->value);
113 struct report entry = report_map_remove(&map, id1);
116 report_map_delete(&map);
139 printf(
"Fixed Strings Example:\n");
140 fixed_string_map map = fixed_string_map_new(stdalloc_get());
146 fixed_string_map_insert(&map, key1, 123);
147 fixed_string_map_insert(&map, key2, 456);
148 fixed_string_map_insert(&map, key3, 789);
150 assert(*fixed_string_map_read(&map, key1) == 123);
151 assert(*fixed_string_map_read(&map, key2) == 456);
152 assert(*fixed_string_map_read(&map, key3) == 789);
154 fixed_string_map_iter_const iter = fixed_string_map_get_iter_const(&map);
156 fixed_string_map_kv_const
const* entry = NULL;
158 while ((entry = fixed_string_map_iter_const_next(&iter))) {
159 printf(
"Position: %zu Key: %.3s Value: %u\n", pos, entry->key->value, *entry->value);
163 fixed_string_map_delete(&map);