diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-06-21 16:19:04 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-06-21 16:19:04 (GMT) |
commit | a21d9f936fe5e795cbea48aa4a4e72adc19e45dd (patch) | |
tree | 3721f8866316884e91ef3caf80b5e6b007c91323 /src/common/dllist.h | |
parent | 0af609c6bf382bffaf3d96383eddf667793f39b4 (diff) |
Restore and update doubly linked lists.
Diffstat (limited to 'src/common/dllist.h')
-rw-r--r-- | src/common/dllist.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/common/dllist.h b/src/common/dllist.h index 1fb010a..f7b500e 100644 --- a/src/common/dllist.h +++ b/src/common/dllist.h @@ -30,17 +30,17 @@ /* Structure à inclure en tête de structure */ -typedef struct _dl_list_item +typedef struct _dl_list_item_t { - struct _dl_list_item *prev; /* Elément précédent */ - struct _dl_list_item *next; /* Elément suivant */ + struct _dl_list_item_t *prev; /* Elément précédent */ + struct _dl_list_item_t *next; /* Elément suivant */ -} dl_list_item; +} dl_list_item_t; -typedef dl_list_item *dl_list_head; +typedef dl_list_item_t *dl_list_head_t; -#define DL_LIST_ITEM(name) dl_list_item name +#define DL_LIST_ITEM(name) dl_list_item_t name #define DL_LIST_ITEM_INIT(item) \ @@ -51,12 +51,15 @@ typedef dl_list_item *dl_list_head; \ } while(0) +#define DL_LIST_HEAD_INIT(head) \ + head = NULL + /* Ajoute un élément dans une liste doublement chaînée. */ -void __dl_list_add(dl_list_item *, dl_list_head *, dl_list_item *, dl_list_item *); +void __dl_list_add(dl_list_item_t *, dl_list_head_t *, dl_list_item_t *, dl_list_item_t *); /* Supprime un élément d'une liste doublement chaînée. */ -void __dl_list_del(dl_list_item *, dl_list_head *); +void __dl_list_del(dl_list_item_t *, dl_list_head_t *); #define dl_list_empty(head) \ @@ -74,7 +77,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *); #define dl_list_add(new, head, type, member) \ do \ { \ - dl_list_item *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member); \ + dl_list_item_t *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member); \ __dl_list_add(&new->member, &hmbr, \ dl_list_empty(*(head)) ? &new->member : hmbr->prev, \ dl_list_empty(*(head)) ? &new->member : hmbr); \ @@ -96,7 +99,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *); #define dl_list_add_tail(new, head, type, member) \ do \ { \ - dl_list_item *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member); \ + dl_list_item_t *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member); \ __dl_list_add(&new->member, &hmbr, \ dl_list_empty(*(head)) ? &new->member : hmbr->prev, \ dl_list_empty(*(head)) ? &new->member : hmbr); \ @@ -107,7 +110,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *); #define dl_list_del(item, head, type, member) \ do \ { \ - dl_list_item *hmbr = &(*head)->member; \ + dl_list_item_t *hmbr = &(*head)->member; \ __dl_list_del(&item->member, &hmbr); \ *(head) = (hmbr ? container_of(hmbr, type, member) : NULL); \ DL_LIST_ITEM_INIT(&item->member); \ @@ -117,7 +120,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *); #define _dl_list_merge(head1, head2) \ do \ { \ - dl_list_item *mid = head1->prev; \ + dl_list_item_t *mid = head1->prev; \ mid->next = head2; \ head1->prev = head2->prev; \ head2->prev->next = head1; \ @@ -131,9 +134,9 @@ void __dl_list_del(dl_list_item *, dl_list_head *); if (dl_list_empty(*head1)) *head1 = *head2; \ else if (!dl_list_empty(*head2)) \ { \ - dl_list_item *hmbr1 = &(*head1)->member; \ - dl_list_item *hmbr2 = &(*head2)->member; \ - dl_list_item *mid = hmbr1->prev; \ + dl_list_item_t *hmbr1 = &(*head1)->member; \ + dl_list_item_t *hmbr2 = &(*head2)->member; \ + dl_list_item_t *mid = hmbr1->prev; \ mid->next = hmbr2; \ hmbr1->prev = hmbr2->prev; \ hmbr2->prev->next = hmbr1; \ @@ -153,7 +156,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *); #define _dl_list_next(iter, head) \ ({ \ - dl_list_item *__next; \ + dl_list_item_t *__next; \ __next = iter->next; \ if (__next == head) \ __next = NULL; \ @@ -192,10 +195,10 @@ void __dl_list_del(dl_list_item *, dl_list_head *); /* Prototype pour un comparateur d'éléments */ -typedef int (*__dl_item_compar_fn_t) (const dl_list_item *, const dl_list_item *); +typedef int (*__dl_item_compar_fn_t) (const dl_list_item_t *, const dl_list_item_t *); /* Trie une liste chaînée en notant les éléments identiques. */ -void sort_dl_list_no_dup(dl_list_head *, size_t *, __dl_item_compar_fn_t, dl_list_head *); +void sort_dl_list_no_dup(dl_list_head_t *, size_t *, __dl_item_compar_fn_t, dl_list_head_t *); |