A Red-Black Tree implementation written by C language
CMIT
C Map
An associative array implemented by C laugnage.
This is an implementation of an associative array. it is similar as C++ <map> but it is implemented by C; thus, this repo calls it cmap (C's <map>).
Implementation
The goal of this repo is providing a binary search tree for the programmers using C language to work on their projects. But, here is only a simple implementation of Red-Black Tree, which is known as a self-balancing binary search tree, and hopes it can be a helpful data structure for the projects written by C language.
cmap is an implementation with OOP style; when using cmap, you must manipulate it as an 'object' in any OOP language.
Usage
Before using cmap, you have to define the three functions with the specific types by yourself at least.
// A comparator for keys of Red-Black Tree.intcmp(constvoid*key1, constvoid*key2) {
/* return negative value, zero, positive value. */;
/* You may understand this quickly if you had used qsort in your C projects. */
}
// A function for getting the memory size of key.size_tkey_size_get(constvoid*key) {
/* returning the size of key. */
}
// A function for getting the memory size of value.size_tval_size_get(constvoid*val) {
/* returning the size of value */
}
In this case, the key and value types of cmap are integer and linked list, respectively.
When you create your linked list data type, there has some details when defining the relative functions.
Ex:
How to destroy entire linked list when it is not used?
How to copy a linked list from another linked list?
Because of the complexity of linked list, you should use CREATE_INTERFACE4 to create a
complete interface to define the behaviors of all methods of struct cmap_data so that
cmap can manipulate the linked list correctly.
$ make adv2.elf
Create the library (shared object)
You can use the cmap by compiling its shared object to your binary exectuable, so here provides a target in makefile to create the shared object in a folder called bin.
This target is set by deafult and It also puts the cmap.h in the folder.