24
24
#include "lib/ilist.h"
25
25
26
26
/*
27
- *removes a node froma list
27
+ *Delete ' node' from list.
28
28
*
29
- * Attention: O(n)
29
+ * It is not allowed to delete a 'node' which is is not in the list 'head'
30
+ *
31
+ * Caution: this is O(n)
30
32
*/
31
33
void
32
34
slist_delete (slist_head * head ,slist_node * node )
@@ -47,9 +49,9 @@ slist_delete(slist_head *head, slist_node *node)
47
49
}
48
50
last = cur ;
49
51
}
52
+ Assert (found );
50
53
51
54
slist_check (head );
52
- Assert (found );
53
55
}
54
56
55
57
#ifdef ILIST_DEBUG
@@ -61,8 +63,11 @@ dlist_check(dlist_head *head)
61
63
{
62
64
dlist_node * cur ;
63
65
64
- if (head == NULL || !(& head -> head ))
65
- elog (ERROR ,"doubly linked list head is not properly initialized" );
66
+ if (head == NULL )
67
+ elog (ERROR ,"doubly linked list head address is NULL" );
68
+
69
+ if (head -> head .next == NULL && head -> head .prev == NULL )
70
+ return ;/* OK, initialized as zeroes */
66
71
67
72
/* iterate in forward direction */
68
73
for (cur = head -> head .next ;cur != & head -> head ;cur = cur -> next )
@@ -96,10 +101,10 @@ slist_check(slist_head *head)
96
101
slist_node * cur ;
97
102
98
103
if (head == NULL )
99
- elog (ERROR ,"singly linked is NULL" );
104
+ elog (ERROR ,"singly linkedlist head address is NULL" );
100
105
101
106
/*
102
- * there isn't much we can test in a singly linked listother that it
107
+ * there isn't much we can test in a singly linked listexcept that it
103
108
* actually ends sometime, i.e. hasn't introduced a cycle or similar
104
109
*/
105
110
for (cur = head -> head .next ;cur != NULL ;cur = cur -> next )