libflint/include/lflinkedlist.h

41 lines
902 B
C
Raw Normal View History

2021-02-01 22:06:37 +00:00
#ifndef LIBFLINT_LL_H
#define LIBFLINT_LL_H
#include <stddef.h>
2021-02-01 22:27:01 +00:00
typedef struct ListNode {
2022-03-28 17:52:16 +00:00
void *data;
struct ListNode *next;
struct ListNode *prev;
2021-02-01 22:27:01 +00:00
} ListNode;
2021-02-01 22:06:37 +00:00
2021-02-01 22:27:01 +00:00
typedef struct {
2021-02-01 22:06:37 +00:00
size_t size;
2022-03-28 17:52:16 +00:00
void (*destroy)(void *data);
2021-02-01 22:06:37 +00:00
2022-03-28 17:52:16 +00:00
int (*match)(const void *a, const void *b);
struct ListNode *head;
struct ListNode *tail;
2021-02-01 22:27:01 +00:00
} List;
2021-02-01 22:06:37 +00:00
2022-03-28 17:52:16 +00:00
void ll_init(List *list, void (*destroy)(void *data));
void ll_destroy(List *list);
int ll_ins_next(List *list, ListNode *node, const void *data);
int ll_ins_prev(List *list, ListNode *node, const void *data);
int ll_remove(List *list, ListNode *node, void **data);
int ll_remove_next(List *list, ListNode *node, void **data);
int ll_remove_prev(List *list, ListNode *node, void **data);
/* Provides ListNode *node for the iteration loop */
#define LL_ITER(list) for(ListNode *node = (list)->head; node != NULL; node = node->next)
2021-02-01 22:06:37 +00:00
#endif