Library of data containers and data structures for C programming language.
Library of data containers and data structures for C programming language. The cdcontainers interface is similar to C ++ STL. The library contains the following data containers:
and following adapters:
Example:
#define CDC_USE_SHORT_NAMES // for short names (functions and structs without prefix cdc_*)
#include <cdcontainers/cdc.h>
#include <stdio.h>
int main(int argc, char** argv)
{
array_t *array = NULL;
if (array_ctor(&array, NULL) != CDC_STATUS_OK)
/* error handling */;
if (array_push_back(array, CDC_FROM_INT(8)) != CDC_STATUS_OK)
/* error handling */;
if (array_push_back(array, CDC_FROM_INT(2)) != CDC_STATUS_OK)
/* error handling */;
for (sizr_t i = 0; i < array_size(array); ++i)
printf("%i\n", CDC_TO_INT(vector_get(v, i)));
array_dtor(array);
}
To build and install cdcontainers from source, the following tools are needed:
On Ubuntu or Debian, you can install them with:
$ sudo apt-get install cmake gcc make libcunit1-dev
To build and install cdstructures, do the following steps:
$ git clone https://github.com/maksimandrianov/cdcontainers
$ cd cdcontainers
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
By default, the package will be installed to /usr/local. However, on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. You can add it, but it may be easier to just install to /usr instead. To do this, invoke cmake as follows:
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
To build and run tests, do the following steps:
$ make tests
$ make check
You can find examples in the directory examples
.
To run the example, compile and link against the cdcontainers library (libcdcontainers.a/.so). If you followed the build steps above, this library will be under the build directory you created.
# Example on linux after running the build steps above. Assumes the
# `cdcontainers` and `build` directories are under the current directory.
$ gcc examples/map.c -isystem include -Llib -lcdcontainers -o map
./map
The output of this program is the following:
Phone book:
Elliott Mooney - (945) 616-4482
Laiba Juarez - (303) 885-5692
Lilia Friedman - (892) 670-4739
Tariq Beltran - (489) 600-7575
Phone book after adding Zak Byers:
Elliott Mooney - (945) 616-4482
Laiba Juarez - (303) 885-5692
Lilia Friedman - (892) 670-4739
Tariq Beltran - (489) 600-7575
Zak Byers - (551) 396-1880
Phone book after erasing Tariq Beltran:
Elliott Mooney - (945) 616-4482
Laiba Juarez - (303) 885-5692
Lilia Friedman - (892) 670-4739
Zak Byers - (551) 396-1880
Phone book after update phone of Zak Byers:
Elliott Mooney - (945) 616-4482
Laiba Juarez - (303) 885-5692
Lilia Friedman - (892) 670-4739
Zak Byers - (555) 396-188