diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-04-05 01:17:39 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-04-05 01:17:39 (GMT) |
commit | 193565c98b3c8df5c18f6f305871d60e2dd88e3b (patch) | |
tree | ff78567a274a5de1340c19b18bb690d27fd87d85 /src/common/dllist.c | |
parent | 4ad9e532a78401f787f0a8a6742095512b520488 (diff) |
Managed double linked lists in a more powerful way.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@56 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common/dllist.c')
-rw-r--r-- | src/common/dllist.c | 87 |
1 files changed, 19 insertions, 68 deletions
diff --git a/src/common/dllist.c b/src/common/dllist.c index 7e56bf4..5de3cd9 100644 --- a/src/common/dllist.c +++ b/src/common/dllist.c @@ -24,9 +24,6 @@ #include "dllist.h" -#include <stdbool.h> - - /****************************************************************************** * * @@ -59,8 +56,8 @@ void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl /****************************************************************************** * * -* Paramètres : prev = élément précédent dans la liste. * -* next = élément suivant dans la liste. * +* Paramètres : item = élément à supprimer. * +* head = adresse d'enregistrement de la tête de la liste. * * * * Description : Supprime un élément d'une liste doublement chaînée. * * * @@ -70,85 +67,39 @@ void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl * * ******************************************************************************/ -void __dl_list_del(dl_list_item *prev, dl_list_item *next) +void __dl_list_del(dl_list_item *item, dl_list_head *head) { - next->prev = prev; - prev->next = next; + item->next->prev = item->prev; + item->prev->next = item->next; -} - - -/****************************************************************************** -* * -* Paramètres : head = début de la liste, à mettre éventuellement à jour. * -* a = premier élément à traiter. * -* b = second élément à traiter. * -* * -* Description : Intervertit deux éléments dans une liste doublement chaînée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void swap_dl_list_items(dl_list_head *head, dl_list_item *a, dl_list_item *b) -{ - bool a_is_head; /* Indique si a est le début */ - bool b_is_head; /* Indique si b est le début */ - dl_list_item tmp; /* Stockage temporaire */ - - a_is_head = (*head == a); - b_is_head = (*head == b); - - /* Liens vers l'extérieur et l'intérieur */ - - if (a->prev != b) a->prev->next = b; - if (a->next != b) a->next->prev = b; - - if (b->prev != a) b->prev->next = a; - if (b->next != a) b->next->prev = a; - - /* Liens propres aux éléments */ - - tmp = *a; - - a->prev = (b->prev == a ? b : b->prev); - a->next = (b->next == a ? b : b->next); - - b->prev = (tmp.prev == b ? a : tmp.prev); - b->next = (tmp.next == b ? a : tmp.next); - - /* Mise à jour éventuelle de la tête */ - - if (a_is_head) *head = b; - else if (b_is_head) *head = a; + if (*head == item) + { + *head = item->next; + if (*head == item) *head = NULL; + } } /****************************************************************************** * * -* Paramètres : list = liste à parcourir. * +* Paramètres : item = point d'insertion. * +* head = seconde liste à intégrer. * * * -* Description : Compte le nombre d'éléments présents dans une liste. * +* Description : Insère une liste au sein d'une autre. * * * -* Retour : Nombre d'éléments comptabilisés. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -unsigned int count_dl_list_items(dl_list_head list) +void __dl_list_splice(dl_list_item *pos, dl_list_head head) { - unsigned int result; /* Résultat à renvoyer */ - dl_list_item *iter; /* Boucle de parcours */ - - result = 0; - - dl_list_for_each(iter, list, dl_list_item *) - result++; + pos->next->prev = head; + head->prev->next = pos->next; - return result; + pos->next = head; + head->prev = pos; } |