GithubHelp home page GithubHelp logo

callumgran / hurust Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 163 KB

GNU-C Macro-based Collections Library

License: GNU General Public License v3.0

Makefile 1.44% Python 1.18% C 97.38%
arraylist c generics heap macros preprocessor priority-queue queue quicksort sort stack vector

hurust's Introduction

HURUST C Macro Collections Library

License LinkToRepo

Stars

HURUST is a versatile, easy to use, header based GNU-C collections library.

Features

  • 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.

Collections Implemented

Dynamic Collections

Collection Abstract Datastructure Datatype
Vector List Dynamic Array
Queue FIFO Dynamic Circular Array
Stack LIFO Dynamic Array
Binary Heap Priority Queue Dynamic Array

Static Collections

Collection Abstract Datastructure Datatype
Array Array Static Array
Queue FIFO Static Circular Array
Stack LIFO Static Array
Hash Set Set Static Hash Table

Extra Features

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"

Getting Started

1. Download

Download the latest release of HURUST from the Releases page and include the hurust directory in your project.

2. Integration

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"

3. Usage

HURUST collections are designed to be easy to use. Simply create a collection template, instatiate an object and perform the desired operations.

Example

#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);
}

Using HURUST as a Single-Header Library (STB)

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.

Downloading the STB

Download the latest single-header release of HURUST from the Releases page. The single-header file is typically named hurust.h.

Integration

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"

Unit Testing

Check the provided unit test examples in the test directory, which showcase the usage of HURUST collections.

Contributing

Contributions are welcome! If you have enhancements or find issues, please open an issue or submit a pull request

hurust's People

Contributors

callumgran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.