pavlosdais / Abstract-Data-Types

A set of efficient data structures in C, created in a generic way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Abstract Data Types in C

This is a modern C library containing implementations designed to provide fast and efficient data structure operations for a wide range of applications while also being educational, having a relatively non-challenging code to follow. All ADTs have been implemented using void pointers to make them generic, allowing the same code to handle different data types (eg integers, strings, structs, etc). The library contains the following ADTs:

The source code of every ADT can be found over at the modules directory.

Usage

The library can be used in your C project by following 3 (simple) steps.

Step 1

Include the header file of the ADT library

#include "lib/ADT.h"

or just include the desired header file(s) of the data structure(s) you want to use.

#include "vector.h"
#include "RedBlackTree.h"
#include "stack.h"
#include "pq.h"
#include "hash_table.h"

Step 2

Depending on the ADT, provide a number of the following functions upon its creation:

  • Destroy function
    Destroys the data allocated for the elements.

  • Compare function
    Compares two Pointers a and b, and returns < 0 if a < b, 0 if a = b or > 0 if a > b.

  • Hash function
    Takes a Pointer and returns a unsigned integer (Used by the hash table).

  • Visit function
    Visits a vertex (Used by the graph).

Step 3

Use ADTlib.a on compilation.

~$ gcc -o my_prog_exec my_prog.c -L. lib/ADTlib.a

Tests

The library comes with a comprehensive suite of tests covering the ADT's, using the acutest library. The tests are located in the tests directory, and are designed to ensure that the library functions as expected. In order to test a certain ADT, navigate to the directory and simply execute:

~$ make run ADT=<ADT>