first commit, initial layout and some ideas I want to implement, included my linked list impl
This commit is contained in:
0
include/nickel/arena.h
Normal file
0
include/nickel/arena.h
Normal file
0
include/nickel/argparse.h
Normal file
0
include/nickel/argparse.h
Normal file
0
include/nickel/bitset.h
Normal file
0
include/nickel/bitset.h
Normal file
0
include/nickel/buf.h
Normal file
0
include/nickel/buf.h
Normal file
0
include/nickel/ctassert.h
Normal file
0
include/nickel/ctassert.h
Normal file
0
include/nickel/defer.h
Normal file
0
include/nickel/defer.h
Normal file
0
include/nickel/hashmap.h
Normal file
0
include/nickel/hashmap.h
Normal file
0
include/nickel/ini.h
Normal file
0
include/nickel/ini.h
Normal file
0
include/nickel/io.h
Normal file
0
include/nickel/io.h
Normal file
62
include/nickel/linkedlist.h
Normal file
62
include/nickel/linkedlist.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef __NICKEL_LINKEDLIST_H_
|
||||
#define __NICKEL_LINKEDLIST_H_
|
||||
|
||||
typedef struct ni_list_node {
|
||||
struct ni_list_node* next;
|
||||
struct ni_list_node* prev;
|
||||
} ni_list_node;
|
||||
|
||||
// sentinel type structure for head + count
|
||||
typedef struct ni_list {
|
||||
ni_list_node head;
|
||||
size_t count;
|
||||
} ni_list;
|
||||
|
||||
// convenience ptr wrapper struct for a 'generic' list of pointers to things
|
||||
typedef struct ni_list_ptr {
|
||||
ni_list_node link;
|
||||
void* ptr;
|
||||
} ni_list_ptr;
|
||||
|
||||
// List functions
|
||||
void ni_list__init(ni_list* l);
|
||||
bool ni_list__is_empty(ni_list* l);
|
||||
|
||||
void ni_list__insert_after(ni_list* l, ni_list_node* entry, ni_list_node* n);
|
||||
void ni_list__insert_before(ni_list* l, ni_list_node* entry, ni_list_node* n);
|
||||
|
||||
void ni_list__push_front(ni_list* l, ni_list_node* n);
|
||||
void ni_list__push_back(ni_list* l, ni_list_node* n);
|
||||
|
||||
void ni_list__remove(ni_list* l, ni_list_node* n);
|
||||
|
||||
static inline ni_list_node* ni_list__get_front(ni_list* l) {
|
||||
// if l is_empty() front == NULL else return the first actual data baring node
|
||||
return ni_list__is_empty(l) ? NULL : l->head.next;
|
||||
}
|
||||
|
||||
static inline ni_list_node* ni_list__get_back(ni_list* l) {
|
||||
// if l is_empty() front == NULL else return the last node in the list
|
||||
return ni_list__is_empty(l) ? NULL : l->head.prev;
|
||||
}
|
||||
|
||||
/* Iter Helpers */
|
||||
|
||||
#define NI_LIST__FOREACH(lptr) \
|
||||
for (ni_list_node* it = ni_list__get_front(lptr); it != &(lptr)->head; it = it->next)
|
||||
|
||||
#define NI_LIST_FOREACH_SAFE(tmp, lptr) \
|
||||
for (ni_list_node* it = ni_list__get_front(lptr), *tmp = it->next; \
|
||||
it != &(lptr)->head; \
|
||||
it = tmp, tmp = it-> next)
|
||||
|
||||
// create a pointer to struct that contains a ni_list_node member
|
||||
// since we know the structure size at compile time we can do some math
|
||||
// to retreive the base address of the structure that contains our list node.
|
||||
#define NI_LIST_CONTAINER_OF(ptr, type, member) \
|
||||
((type*)((uint8_t*)(ptr) - offsetof(type, member)))
|
||||
|
||||
#endif /* __NICKEL_LINKEDLIST_H_ */
|
||||
0
include/nickel/log.h
Normal file
0
include/nickel/log.h
Normal file
0
include/nickel/refcnt.h
Normal file
0
include/nickel/refcnt.h
Normal file
0
include/nickel/result.h
Normal file
0
include/nickel/result.h
Normal file
0
include/nickel/ring_spsc.h
Normal file
0
include/nickel/ring_spsc.h
Normal file
0
include/nickel/span.h
Normal file
0
include/nickel/span.h
Normal file
0
include/nickel/threadpool.h
Normal file
0
include/nickel/threadpool.h
Normal file
0
include/nickel/timeutil.h
Normal file
0
include/nickel/timeutil.h
Normal file
0
include/nickel/version.h
Normal file
0
include/nickel/version.h
Normal file
0
include/nickel/xalloc.h
Normal file
0
include/nickel/xalloc.h
Normal file
Reference in New Issue
Block a user