1 /*-------------------------------------------------------------------------
4 * support for integrated/inline doubly- and singly- linked lists
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/lib/ilist.c
14 * This file only contains functions that are too big to be considered
15 * for inlining. See ilist.h for most of the goodies.
17 *-------------------------------------------------------------------------
22 #define ILIST_INCLUDE_DEFINITIONS
24 #include "lib/ilist.h"
27 * Delete 'node' from list.
29 * It is not allowed to delete a 'node' which is not in the list 'head'
31 * Caution: this is O(n); consider using slist_delete_current() instead.
34 slist_delete(slist_head *head, slist_node *node)
36 slist_node *last = &head->head;
38 bool found PG_USED_FOR_ASSERTS_ONLY = false;
40 while ((cur = last->next) != NULL)
44 last->next = cur->next;
45 #ifdef USE_ASSERT_CHECKING
59 * Verify integrity of a doubly linked list
62 dlist_check(dlist_head *head)
67 elog(ERROR, "doubly linked list head address is NULL");
69 if (head->head.next == NULL && head->head.prev == NULL)
70 return; /* OK, initialized as zeroes */
72 /* iterate in forward direction */
73 for (cur = head->head.next; cur != &head->head; cur = cur->next)
78 cur->prev->next != cur ||
79 cur->next->prev != cur)
80 elog(ERROR, "doubly linked list is corrupted");
83 /* iterate in backward direction */
84 for (cur = head->head.prev; cur != &head->head; cur = cur->prev)
89 cur->prev->next != cur ||
90 cur->next->prev != cur)
91 elog(ERROR, "doubly linked list is corrupted");
96 * Verify integrity of a singly linked list
99 slist_check(slist_head *head)
104 elog(ERROR, "singly linked list head address is NULL");
107 * there isn't much we can test in a singly linked list except that it
108 * actually ends sometime, i.e. hasn't introduced a cycle or similar
110 for (cur = head->head.next; cur != NULL; cur = cur->next)
114 #endif /* ILIST_DEBUG */