Skip to content
/ libds Public

🧱 Data structures implemented in C

License

Notifications You must be signed in to change notification settings

tmzane/libds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libds

Data structures implemented in C.

Map

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.

About

🧱 Data structures implemented in C

Topics

Resources

License

Stars

Watchers

Forks