summaryrefslogtreecommitdiff
path: root/src/ll.h
blob: 5e47bd9c01e77f672d491801d5bbb24c254820d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef __VXGG_REWRITE___SHARED_H___28542989122405___
#define __VXGG_REWRITE___SHARED_H___28542989122405___

#include <stddef.h>

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