String + generic data structures library in C.
Appendix
This is library written in C that provides easy-to-use implementations of fundamental data structures and a custom string type. It aims to reduce boilerplate and simplify development for C projects that require dynamic arrays, stacks, queues, or hash tables.
Features
- A custom string type with functions to create, destroy, and query size/capacity.
- Dynamic arrays (vectors)
- Stacks
- Queues
- Hash tables (hashmaps)
Tech Stack
Languages: C
Build: Make and Docker
Installation
Clone the project
git clone https://codeberg.org/luizvilasboas/libstd.git
Go to the project directory
Compile the library
Install the library
Usage/Examples
#include <libstd/data_structures/vector.h>
#include <stdio.h>
int compare_ints(void *a, void *b) {
return (*(int *)a - *(int *)b);
}
int main() {
int data_1 = 5, data_2 = 2, data_3 = 8;
printf(
"Element %zu: %d\n", i, *(
int *)
vector_get(&vector, i));
}
return 0;
}
Structure representing a generic linked-list-backed Vector.
Definition vector.h:18
void vector_destroy(Vector *vector)
Destroys the Vector and frees all allocated nodes and their associated data.
Definition vector.c:39
void * vector_get(Vector *vector, size_t index)
Retrieves a pointer to the element at a specific index.
Definition vector.c:128
int vector_size(const Vector *vector)
Retrieves the total number of elements currently stored in the vector.
Definition vector.c:162
bool vector_insert(Vector *vector, const void *data)
Appends (inserts) a new element to the end of the vector.
Definition vector.c:61
bool vector_sort(Vector *vector, int(*cmp_fn)(void *, void *))
Sorts the elements in the vector using a comparison function.
Definition vector.c:170
void vector_init(Vector *vector, size_t element_size)
Initializes an empty Vector.
Definition vector.c:29
Documentation
"" "Documentation"
Running Tests
To run tests, run the following command
Contributing
If you have a suggestion that would make this better, please fork the repo and create a pull request.
License
LGPLv3