trunk: changeset 14

Sat, 20 May 2000 17:43:36 +0200

author
tuomov
date
Sat, 20 May 2000 17:43:36 +0200
changeset 11
3ea4e7930c5b
parent 10
ab335fe0d26d
child 12
5fd153b29d40

trunk: changeset 14
Added dlist.h for doubly linked lists.

include/libtu/dlist.h file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libtu/dlist.h	Sat May 20 17:43:36 2000 +0200
@@ -0,0 +1,70 @@
+/*
+ * libtu/common.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2000. 
+ * See the included file LICENSE for details.
+ */
+
+#ifndef LIBTU_DLIST_H
+#define LIBTU_DLIST_H
+
+#define LINK_ITEM(LIST, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=NULL;                    \
+	if((LIST)==NULL){                     \
+		(LIST)=(ITEM);                    \
+		(ITEM)->PREV=(ITEM);              \
+	}else{                                \
+		(ITEM)->PREV=(LIST)->PREV;        \
+		(ITEM)->PREV->NEXT=(ITEM);        \
+		(LIST)->PREV=(ITEM);              \
+	}
+
+
+#define LINK_ITEM_FIRST(LIST, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(LIST);                        \
+	if((LIST)==NULL){                           \
+		(ITEM)->PREV=(ITEM);                    \
+	}else{                                      \
+		(ITEM)->PREV=(LIST)->PREV;              \
+		(LIST)->PREV=(ITEM);                    \
+	}                                           \
+	(LIST)=(ITEM);
+
+
+#define LINK_ITEM_LIST LINK_ITEM
+
+
+#define LINK_ITEM_BEFORE(LIST, BEFORE, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(BEFORE);                               \
+	(ITEM)->PREV=(BEFORE)->PREV;                         \
+	(BEFORE)->PREV=(ITEM);                               \
+	if((BEFORE)==(LIST))                                 \
+		(LIST)=(ITEM);                                   \
+	else                                                 \
+		(ITEM)->PREV->NEXT=(ITEM)
+
+
+#define LINK_ITEM_AFTER(LIST, AFTER, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(AFTER)->NEXT;                        \
+	(ITEM)->PREV=(AFTER);                              \
+	(AFTER)->NEXT=(ITEM);                              \
+	if((ITEM)->NEXT==NULL)                             \
+		(LIST)->PREV=(ITEM);                           \
+	else                                               \
+		(ITEM)->NEXT->PREV=ITEM;
+
+
+#define UNLINK_ITEM(LIST, ITEM, NEXT, PREV) \
+	if((ITEM)==(LIST)){                     \
+		(LIST)=(ITEM)->NEXT;                \
+		if((LIST)!=NULL)                    \
+			(LIST)->PREV=(ITEM)->PREV;      \
+	}else if((ITEM)->NEXT==NULL){           \
+		(ITEM)->PREV->NEXT=NULL;            \
+		(LIST)->PREV=(ITEM)->PREV;          \
+	}else{                                  \
+		(ITEM)->PREV->NEXT=(ITEM)->NEXT;    \
+		(ITEM)->NEXT->PREV=(ITEM)->PREV;    \
+	}
+
+#endif /* LIBTU_DLIST_H */

mercurial