summaryrefslogtreecommitdiff
path: root/src/utils/list.h
diff options
context:
space:
mode:
authorBo Yang <struggleyb.nku@gmail.com>2009-08-11 11:17:23 +0000
committerBo Yang <struggleyb.nku@gmail.com>2009-08-11 11:17:23 +0000
commit399da01ae4eb5c5e3e9349bacc2063c946c3d4a1 (patch)
tree433c8bcde94fc7a6e6f2e5cbf23842a84db98146 /src/utils/list.h
parenteec057c7437e19b59ca1e698ce548cb56ce37240 (diff)
downloadlibdom-399da01ae4eb5c5e3e9349bacc2063c946c3d4a1.tar.gz
libdom-399da01ae4eb5c5e3e9349bacc2063c946c3d4a1.tar.bz2
Merge the branches/struggleyb/libdom-remain back to trunk.
svn path=/trunk/dom/; revision=9191
Diffstat (limited to 'src/utils/list.h')
-rw-r--r--src/utils/list.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/utils/list.h b/src/utils/list.h
new file mode 100644
index 0000000..6e3ba20
--- /dev/null
+++ b/src/utils/list.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ *
+ * This file contains the list structure used to compose lists.
+ *
+ * Note: This is a implementation of a doubld-linked cyclar list.
+ */
+
+#ifndef dom_utils_list_h_
+#define dom_utils_list_h_
+
+#include <stddef.h>
+
+struct list_entry {
+ struct list_entry *prev;
+ struct list_entry *next;
+};
+
+/**
+ * Initialise a list_entry structure
+ *
+ * \param ent The entry to initialise
+ */
+static inline void list_init(struct list_entry *ent)
+{
+ ent->prev = ent;
+ ent->next = ent;
+}
+
+/**
+ * Append a new list_entry after the list
+ *
+ * \param head The list header
+ * \param new The new entry
+ */
+static inline void list_append(struct list_entry *head, struct list_entry *new)
+{
+ new->next = head;
+ new->prev = head->prev;
+ head->prev->next = new;
+ head->prev = new;
+}
+
+/**
+ * Delete a list_entry from the list
+ *
+ * \param entry The entry need to be deleted from the list
+ */
+static inline void list_del(struct list_entry *ent)
+{
+ ent->prev->next = ent->next;
+ ent->next->prev = ent->prev;
+
+ ent->prev = ent;
+ ent->next = ent;
+}
+
+#endif