From c1b188af8c51e29c96a0422b79516d95696869e7 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Wed, 12 Feb 2025 16:47:43 -0600 Subject: Implement a linked list struct --- src/ll.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/ll.h (limited to 'src/ll.h') diff --git a/src/ll.h b/src/ll.h new file mode 100644 index 0000000..5e47bd9 --- /dev/null +++ b/src/ll.h @@ -0,0 +1,35 @@ +#ifndef __VXGG_REWRITE___SHARED_H___28542989122405___ +#define __VXGG_REWRITE___SHARED_H___28542989122405___ + +#include + +typedef struct dll { + void *data; + int (*dfreecb)(void*); + + struct dll *next; + struct dll *prev; +} dllnode; + +typedef struct { + dllnode *start; + dllnode *end; + size_t size; +} dlinkedlist; + +// Initialize a dlinkedlist +void dlinkedlist_init(dlinkedlist **ll); + +// Free a dlinkedlist and its elements +void dlinkedlist_free(dlinkedlist **ll); + +// Insert an element to the beginning of the list +int dlinkedlist_insert(dlinkedlist * const ll, void *data, int (*dfreecb)(void*)); + +// Insert an element to the end of the list +int dlinkedlist_append(dlinkedlist * const ll, void *data, int (*dfreecb)(void*)); + +// Get the element from a dlinkedlist at index +dllnode *dlinkedlist_get(const dlinkedlist * const ll, size_t index); + +#endif \ No newline at end of file -- cgit v1.2.3