Giter Club home page Giter Club logo

gonlibs's Introduction

gonlibs

Libraries of generic stuff written in C for my projects and yours. ;)

Contents

  • ADT
    • stack
    • dequeue
    • hashtable
    • forwardlist
  • MEM
    • memwrapper

ADT

stack

A generic LIFO queue. A stack.

stack_t  stack_new  (void);
bool     stack_empty(stack_t stack);
void     stack_push (stack_t stack, void *elem);
void    *stack_pop  (stack_t stack);
void     stack_free (stack_t *stack, void (*elem_free)(void *));

dequeue

A generic double-ended queue.

dequeue_t dequeue_new (void);
void      dequeue_free(dequeue_t *dequeue, void (*elem_free)(void *));

// Capacity
bool dequeue_isempty(dequeue_t dequeue);

// Modifiers
void  dequeue_push_back (dequeue_t dequeue, void *elem);
void  dequeue_push_front(dequeue_t dequeue, void *elem);
void *dequeue_pop_back  (dequeue_t dequeue);
void *dequeue_pop_front (dequeue_t dequeue);
void  dequeue_clear     (dequeue_t dequeue, void (*elem_free)(void *));

hashtable

A generic hashtable. Stores pairs of type <int, T>.

hashtable_t hashtable_new (void);
void        hashtable_free(hashtable_t *hashtable, void (*elem_free)(void *));

// Capacity
bool      hashtable_isempty(hashtable_t hashtable);
uintmax_t hashtable_size   (hashtable_t hashtable);

// Modifiers
void  hashtable_insert(hashtable_t hashtable, int key, void *elem);
void *hashtable_remove(hashtable_t hashtable, int key);
void  hashtable_clear (hashtable_t hashtable, void (*elem_free)(void *));

// Operations
void *hashtable_find(hashtable_t hashtable, int key);

forwardlist

A generic single-linked list with simplicity built in to it.

T    forwardlist_new (void *elem, ...);
void forwardlist_free(T *list);

// Capacity
bool      forwardlist_empty(T list);
uintmax_t forwardlist_size (T list);

// Iterators
forwardlist_iterator_t   forwardlist_begin(T list);
forwardlist_iterator_t   forwardlist_end  (T list);
forwardlist_iterator_t   forwardlist_next (T list, forwardlist_iterator_t it);
void                   **forwardlist_deref(forwardlist_iterator_t it);

// Modifiers
void  forwardlist_push_front(T list, void *elem);
void *forwardlist_pop_front (T list);
void  forwardlist_append    (T list, T tail);
void  forwardlist_map       (T list,
        void apply(void **x, void *cl), void *cl);
void  forwardlist_clear     (T list);

// Operations
void   forwardlist_reverse (T list);
void **forwardlist_to_array(T list, void *end);

// To be added
void   forwardlist_insert_after(T list, const uintmax_t pos, void *elem);
void   forwardlist_erase_after (T list, const void *pos);
T      forwardlist_copy        (T list);

MEM

memwrapper

A simple wrapper for standard memory calls. Not all of them yet and nothing special. Brevity is the soul of wit.

#define ALLOC (nbytes)        (memwrap_malloc((nbytes), __FILE__, __LINE__))
#define CALLOC(count, nbytes) (memwrap_calloc((count), (nbytes), __FILE__, __LINE__))
#define NEW   (ptr)           ((ptr) = ALLOC((int64_t)sizeof *(ptr)))
#define NEWZ  (ptr)           ((ptr) = CALLOC(1, (int64_t)sizeof *(ptr)))
#define RESIZE(ptr, nbytes)   ((ptr) = memwrap_resize((ptr), (nbytes), __FILE__, __LINE__))
#define FREE  (ptr)           ((void)memwrap_free((ptr), __FILE__, __LINE__), (ptr) = NULL)

void *memwrap_malloc(int64_t nbytes, const char *file, int line);
void *memwrap_calloc(int64_t count, int64_t nbytes, const char *file, int line);
void *memwrap_resize(void *ptr, int64_t nbytes, const char *file, int line);
void  memwrap_free  (void *ptr, const char *file, int line);

gonlibs's People

Contributors

gon1332 avatar

Watchers

James Cloos avatar  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.