HURUST is a versatile, easy to use, header based GNU-C collections library.
-
Fully Macro-Based: HURUST is fully macro-based, meaning that it is simple to use with minimal boilerplate code.
-
Dynamic and Static Collections: HURUST offers both dynamically and statically sized collections.
-
Sorting: Sort collections easily using built-in sorting macro's.
-
Memory Management: HURUST collections require a memory management object to be passed in, allowing for easy integration with your project's memory management system.
Collection | Abstract Datastructure | Datatype |
---|---|---|
Vector | List | Dynamic Array |
Queue | FIFO | Dynamic Circular Array |
Stack | LIFO | Dynamic Array |
Binary Heap | Priority Queue | Dynamic Array |
Collection | Abstract Datastructure | Datatype |
---|---|---|
Array | Array | Static Array |
Queue | FIFO | Static Circular Array |
Stack | LIFO | Static Array |
Hash Set | Set | Static Hash Table |
Feature | Description | Header File |
---|---|---|
Lambda Expressions | Support for lambda expressions and anonymous functions in C | #include "lambda.h" |
Allocator | Basic allocator struct and macros | #include "alloc.h" |
Sorting | Sorting macro that can be applied on any array | #include "sort.h" |
Download the latest release of HURUST from the Releases page and include the hurust directory in your project.
Include the appropriate collection header file in your project:
For static collections:
#include "hurust/static/collection_name.h"
For dynamic collections:
#include "hurust/dynamic/collection_name.h"
HURUST collections are designed to be easy to use. Simply create a collection template, instatiate an object and perform the desired operations.
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#include "hurust/functional/lambda.h"
#include "hurust/dynamic/vector.h"
int main(void)
{
// Create a vector of integers
VECTOR(int, int);
struct int_vector_t vector;
vector_init(&vector, HR_GLOBAL_ALLOCATOR, 2,
lambda(int, (const int a, const int b), { return a - b; }));
// Push some elements onto the vector
vector_push(&vector, &(int){1});
vector_push(&vector, &(int){3});
vector_push(&vector, &(int){2});
// Sort the vector
vector_sort(&vector);
// Assert the vector is sorted
assert(anon(
bool, (int *arr, size_t size),
{
for (size_t i = 0; i < (size - 1); i++) {
if (arr[i] > arr[i + 1]) {
return false;
}
}
return true;
},
vector_get_data(&vector), vector_get_size(&vector)));
// Pop an element off the vector
int pop = vector_pop(&vector, 2);
// Print the vector
vector_foreach(&vector, lambda(void, (const int *const element), {
printf("%d\n", *element);
}));
// Free the vector
vector_free(vec);
}
HURUST can be easily integrated into your project as a single-header library (STB), simplifying the setup process and making it convenient for small to medium-sized projects.
Download the latest single-header release of HURUST from the Releases page. The single-header file is typically named hurust.h.
Copy the downloaded hurust.h header file into your project's source code directory. Include the HURUST header file in your C code:
#define HURUST_IMPLEMENTATION
#include "hurust.h"
Check the provided unit test examples in the test directory, which showcase the usage of HURUST collections.
Contributions are welcome! If you have enhancements or find issues, please open an issue or submit a pull request