(c) 2011-2019 @marekweb
Lists and hashtables are two of the most common generic data types.
This library implements lists (as arrays, or "arraylists") and hashtables (with open addressing, linear probing) in pure C.
It aims to be simple and concise, while being completely generic.
It uses void pointers (void*
) as its value type in order to remain generic. In other words, you can use it to store any kind of reference values, including strings.
The code follows the C99 standard. If you're compiling using gcc
, use the -std=c99
flag.
You can use arraylist.c and hashtable.c by placing them in your project.
This library uses headers generated by makeheaders
. The #if INTERFACE
lines are artifacts of this. You don't have to worry about this if you're not making changes to the files.
The arraylist.c
file contains an arraylist implementation. It is implemented as a dynamic array which is automatically resized as needed.
Usage:
arraylist* mylist = arraylist_create();
arraylist_add(mylist, value);
void* result = arraylist_pop(mylist);
The hashtable.c
file contains a hashtable implementation. It is implemented with open addressing and linear probing. It is automatically resized as needed.
Usage:
hashtable* mytable = hashtable_create();
hashtable_set(mytable, "foo", value1);
hashtable_remove(mytable, "boo");
void* result = hashtable_get(mytable, "bar");