25 printf(
"Map has items:\n");
26 id_to_name_iter_const iter = id_to_name_get_iter_const(map);
28 printf(
"position: %zu key: %" PRIu32
" string: %s\n", pos, *entry.key, *entry.value);
33 printf(
"Id to Name Map Example:\n");
34 id_to_name map = id_to_name_new();
36 id_to_name_insert(&map, 23,
"hello");
37 id_to_name_insert(&map, 10,
"bob");
38 id_to_name_insert(&map, 42,
"meaning");
39 ASSERT(strcmp(*id_to_name_read(&map, 42),
"meaning") == 0);
44 ASSERT((entry = id_to_name_write(&map, 23)));
45 *entry =
"a different string!";
49 id_to_name_delete(&map);
85 printf(
"Report Map Example:\n");
86 report_map map = report_map_new();
88 struct report_id id1 = {.name = strdup(
"Report A"), .section = 1};
89 struct report_id id2 = {.name = strdup(
"Report B"), .section = 2};
91 report_map_insert(&map, id1,
92 (
struct report){.description = strdup(
"Description A"), .value = 100});
93 report_map_insert(&map, id2,
94 (
struct report){.description = strdup(
"Description B"), .value = 200});
96 assert(strcmp(report_map_read(&map, id1)->description,
"Description A") == 0);
98 report_map_iter_const iter = report_map_get_iter_const(&map);
100 printf(
"Position: %zu Key: %s Section: %u Value: %d\n", pos, entry.key->name,
101 entry.key->section, entry.value->value);
104 struct report entry = report_map_remove(&map, id1);
107 report_map_delete(&map);
130 printf(
"Fixed Strings Example:\n");
131 fixed_string_map map = fixed_string_map_new();
137 fixed_string_map_insert(&map, key1, 123);
138 fixed_string_map_insert(&map, key2, 456);
139 fixed_string_map_insert(&map, key3, 789);
141 assert(*fixed_string_map_read(&map, key1) == 123);
142 assert(*fixed_string_map_read(&map, key2) == 456);
143 assert(*fixed_string_map_read(&map, key3) == 789);
145 fixed_string_map_iter_const iter = fixed_string_map_get_iter_const(&map);
146 ITER_ENUMERATE_LOOP(fixed_string_map_iter_const, iter, fixed_string_map_kv_const, entry,
size_t,
148 printf(
"Position: %zu Key: %.3s Value: %u\n", pos, entry.key->value, *entry.value);
151 fixed_string_map_delete(&map);
#define ITER_ENUMERATE_LOOP(ITER_TYPE, ITER_NAME, VALUE_TYPE, VALUE_NAME, COUNTER_TYPE, COUNTER_NAME)