diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-02-13 17:02:19 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2022-02-13 17:02:44 +0100 |
| commit | 12b6c9dfd009352e0bb7f8395abd3678e3bd6265 (patch) | |
| tree | 189a16dae165e97cb87acb5f6233edfd17004e31 /src/list.h | |
| parent | 96e9e044e779b301b0608aea0ee4449124a8d0bd (diff) | |
| download | tmus-12b6c9dfd009352e0bb7f8395abd3678e3bd6265.tar.gz tmus-12b6c9dfd009352e0bb7f8395abd3678e3bd6265.zip | |
Added liblist
Diffstat (limited to 'src/list.h')
| -rw-r--r-- | src/list.h | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/list.h b/src/list.h deleted file mode 100644 index a18068a..0000000 --- a/src/list.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include <stdlib.h> - -#define LINK_OFFSET(type) ((size_t) &((type *)0)->link) -#define UPCAST(ptr, type) ({ \ - const typeof( ((type *)0)->link ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - LINK_OFFSET(type) ); }) - -#define LINK_EMPTY ((struct link) { 0 }) - -#define LINK(p) (&(p)->link) - -#define LIST_INNER(list, link) \ - (((link) != &(list)->head) && ((link) != &(list)->tail)) - -#define LIST_ITER(list, iter) (iter) = (list)->head.next; \ - (iter) != &(list)->tail; (iter) = (iter)->next - -typedef void (*link_free_func)(void *p); - -struct link { - struct link *prev; - struct link *next; -}; - -struct list { - struct link head; - struct link tail; -}; - -void list_init(struct list *list); -void list_free(struct list *list, void (*free_item)(void *), int offset); -int list_empty(struct list *list); -int list_len(struct list *list); -struct link *list_at(struct list *list, int n); -void list_push_front(struct list *list, struct link *link); -void list_push_back(struct list *list, struct link *link); -struct link *list_pop_front(struct list *list); -struct link *list_pop_back(struct list *list); - -void link_prepend(struct link *list, struct link *link); -void link_append(struct link *list, struct link *link); -struct link *link_iter(struct link *link, int n); -struct link *link_pop(struct link *link); - |
