summaryrefslogtreecommitdiffstats
path: root/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'list.c')
-rw-r--r--list.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/list.c b/list.c
index 9cf1ad0..a05aab2 100644
--- a/list.c
+++ b/list.c
@@ -1,4 +1,3 @@
-#include <stddef.h>
#include "list.h"
struct _list {
@@ -11,6 +10,26 @@ void list_init(struct list *list) {
list->end = list;
}
+int list_empty(struct list *list) {
+ return list->head == list->end;
+}
+
+int list_singleton(struct list *list) {
+ return list->head == list->tail && list->head != list->end;
+}
+
+void *list_circular_prev(void *_node) {
+ struct _list *node = _node;
+ do { node = node->prev; } while (node == node->listhead);
+ return node;
+}
+
+void *list_circular_next(void *_node) {
+ struct _list *node = _node;
+ do { node = node->next; } while (node == node->listhead);
+ return node;
+}
+
void list_insert(void *_next, void *_node) {
struct _list *node = _node;
struct _list *next = _next;
@@ -19,6 +38,7 @@ void list_insert(void *_next, void *_node) {
prev->next = node;
node->next = next;
node->prev = prev;
+ node->listhead = next->listhead;
}
void list_remove(void *_node) {
@@ -27,6 +47,4 @@ void list_remove(void *_node) {
struct _list *prev = node->prev;
next->prev = prev;
prev->next = next;
- node->next = NULL;
- node->prev = NULL;
}