From b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Thu, 27 Jan 2022 03:29:44 +0100 Subject: New list interface for fast tail access --- src/list.h | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index b0e174d..a18068a 100644 --- a/src/list.h +++ b/src/list.h @@ -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); + -- cgit v1.2.3-71-gd317