From 7083f1d8f72d4e45a82fd40cd4822356429f0e23 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 24 Mar 2025 15:02:03 -0500 Subject: Refactor a bunch of the linked list implementation --- src/ll.h | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'src/ll.h') diff --git a/src/ll.h b/src/ll.h index 5e47bd9..f5846fb 100644 --- a/src/ll.h +++ b/src/ll.h @@ -1,35 +1,19 @@ -#ifndef __VXGG_REWRITE___SHARED_H___28542989122405___ -#define __VXGG_REWRITE___SHARED_H___28542989122405___ +#ifndef __VXGG_REWRITE___LL_H___305861098005___ +#define __VXGG_REWRITE___LL_H___305861098005___ #include -typedef struct dll { - void *data; - int (*dfreecb)(void*); +typedef int (*dlinkedlist_freecallback)(void*); +typedef struct dlinkedlist dlinkedlist; - 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); +int dlinkedlist_insert(dlinkedlist * const ll, void *data, dlinkedlist_freecallback dfreecb); +int dlinkedlist_append(dlinkedlist * const ll, void *data, dlinkedlist_freecallback dfreecb); +void *dlinkedlist_get(const dlinkedlist * const ll, size_t index); +void *dlinkedlist_getfirst(const dlinkedlist * const ll); +void *dlinkedlist_getlast(const dlinkedlist * const ll); +int dlinkedlist_remove(dlinkedlist * const ll, size_t index); #endif \ No newline at end of file -- cgit v1.2.3