Code Monkey home page Code Monkey logo

hutils's Introduction

hutils - Utilities for C/C++ programming

A fast dynamic array library for C/C++ similar to C++'s std::vector.

#include "light_array.h"

int main(int argc, char** argv)
{
    int* buffer = array_new(int);

    array_push(buffer, 1);  // [1]
    array_push(buffer, 2);  // [1, 2]
    array_push(buffer, 3);  // [1, 2, 3]
    array_push(buffer, 4);  // [1, 2, 3, 4]
    array_push(buffer, 5);  // [1, 2, 3, 4, 5]
    
    int five = array_pop(buffer);       // [1, 2, 3, 4]

    array_remove(buffer, 1);            // [1, 4, 3]
    array_remove_ordered(buffer, 0);    // [4, 3]

    array_free(buffer); 

    return 0;
}

A fast memory arena allocator library for C/C++.

#include "light_arena.h"

int main(int argc, char** argv)
{
    Light_Arena* arena = arena_create(512);

    void* m1 = arena_alloc(arena, 64);
    void* m2 = arena_alloc(arena, 84);

    arena_free(arena);

    return 0;
}

A minimal OpenGL extensions library for C/C++.

#define HOGL_IMPLEMENT // only in one compilation unit
#include "ho_gl.h"

int main(int argc, char** argv) {
    // Initialize OpenGL and get a context
    // hogl_init_opengl is an alternative for windows

    if(hogl_init_gl_extensions() == -1) {
        // Error handling ...
    }

    // Use OpenGL extensions

    return 0;
}

A growing hash table implementation for C/C++.

#include <stdio.h>
#define HOHT_IMPLEMENTATION
#include "hoht.h"

int main() {
    // 10 initial capacity, 50% occupancy ratio
    Hoht_Table table = {0};
    hoht_new(&table, 10, sizeof(int), 0.5f, malloc, free);

    int a = 1;
    int b = 2;
    int c = 3;

    hoht_push(&table, "Hello1", &a);
    hoht_push(&table, "Hello2", &b);
    hoht_push(&table, "Hello3", &c);

    int a_res;
    hoht_get(&table, "Hello1", &a_res);

    int b_res = *(int*)hoht_get_value(&table, "Hello2");

    // will print 
    // a is: 1 and b is: 2
    printf("a is: %d and b is: %d\n", a_res, b_res);
}

hutils's People

Contributors

hoshoyo avatar

Stargazers

 avatar Harsh Panchal 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.