diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-01-27 03:29:44 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2022-01-27 03:29:44 +0100 |
| commit | b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d (patch) | |
| tree | 253551dcba2f3798f9d6c4b6f8a9a820381eb31a /src/list.h | |
| parent | e456776063b61d339205c84bf884d0eeb761e57b (diff) | |
| download | tmus-b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d.tar.gz tmus-b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d.zip | |
New list interface for fast tail access
Diffstat (limited to 'src/list.h')
| -rw-r--r-- | src/list.h | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -7,29 +7,40 @@ const typeof( ((type *)0)->link ) *__mptr = (ptr); \ (type *)( (char *)__mptr - LINK_OFFSET(type) ); }) -#define LIST_HEAD ((struct link) { .prev = NULL, .next = NULL }) #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; }; -/* list_XXX functions operate on the list head */ +struct list { + struct link head; + struct link tail; +}; -void list_free(struct link *head, void (*free_item)(void *), int offset); -int list_empty(struct link *head); -int list_len(struct link *head); -int list_ffind(struct link *head, struct link *link); -struct link *list_at(struct link *head, int n); -void list_push_front(struct link *head, struct link *link); -void list_push_back(struct link *head, struct link *link); -struct link *list_pop_front(struct link *head); +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_back(struct link *list); -struct link *link_pop(struct link *link); struct link *link_iter(struct link *link, int n); +struct link *link_pop(struct link *link); + |
