negrel / cvector

Simple data structure library in C.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NDS

Simple data structure library in C.

Build the library

Run the following command to build the library in build/libcvector.a:

$ make build

If you want to build it in a docker container:

$ make docker_build

How it works

CVector is composed of two parts, the header and the body. The headers contains privates information such as the length and capacity of the vector. The body contains inserted data.

The headers and body are laid out next two each other as follow:

0x00                                         0xFF
┌───────────┬──────────────────────────────────┐
│  Headers  │               Body               │
└───────────┴──────────────────────────────────┘

Therefore, when the vector needs to grow, it allocate a new vector with a capacity twice as big and copy all elements from the old vector.
When a vector grow (e.g. vector_push and vector_unshift), it also free the old one.
Thus, to avoid double free error or segmentation fault you must not copy vector pointers and add a level of indirection instead.

Documentation

Functions are commented in header file.

🌠 Show your support

Please give a ⭐ if this project helped you!

📜 License

MIT © Alexandre Negrel

About

Simple data structure library in C.

License:MIT License


Languages

Language:C 92.2%Language:Makefile 7.2%Language:Dockerfile 0.6%