Skip to content

xizho10/datastructs-c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

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

About

Arraylist and Hashtable implementation in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published