Data structures implemented in C.
A hash map with support for dynamic resizing and custom allocators.
map* m = map_new(NULL);
map_get(m, "foo"); // -> NULL
map_len(m); // -> 0
map_set(m, "foo", "bar"); // -> "bar"
map_get(m, "foo"); // -> "bar"
map_len(m); // -> 1
map_set(m, "foo", "baz"); // -> "bar"
map_get(m, "foo"); // -> "baz"
map_len(m); // -> 1
map_del(m, "foo"); // -> "baz"
map_len(m); // -> 0
for (struct map_iter it = map_iter_new(m); map_iter_next(&it);) {
// it.key
// it.value
}
map_free(m);
There are two implementations: open addressing (map_oa.c) and separate chaining (map_sc.c). Both are based on information from Wikipedia and the book Crafting interpreters. The hash function used is FNV-1a.