Skip to content

Latest commit

 

History

History
48 lines (31 loc) · 1.46 KB

README.md

File metadata and controls

48 lines (31 loc) · 1.46 KB

Arraylist and Hashtable in C

(c) 2011 @marekweb

Objective

Lists and mappings are two of the most common generic data types. This library implements both, independantly, 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.

Use in your project

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.

Arraylists

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);

Hashtables

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");