summaryrefslogtreecommitdiff
path: root/cesar/lib/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/lib/list.h')
-rw-r--r--cesar/lib/list.h191
1 files changed, 191 insertions, 0 deletions
diff --git a/cesar/lib/list.h b/cesar/lib/list.h
new file mode 100644
index 0000000000..042236ac65
--- /dev/null
+++ b/cesar/lib/list.h
@@ -0,0 +1,191 @@
+#ifndef lib_list_h
+#define lib_list_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file lib/list.h
+ * \brief Double linked lists.
+ * \ingroup lib
+ */
+
+/** Double linked list node. */
+struct list_node_t
+{
+ /** Pointer to next node. */
+ struct list_node_t *next;
+ /** Pointer to previous node. */
+ struct list_node_t *prev;
+};
+typedef struct list_node_t list_node_t;
+
+/** Double linked list. */
+struct list_t
+{
+ /** List NIL element. */
+ list_node_t nil;
+};
+typedef struct list_t list_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise a double linked list.
+ * \param list the list to initialise
+ */
+void
+list_init (list_t *list);
+
+/**
+ * Initialise a list node.
+ * \param node the node to initialise
+ */
+void
+list_init_node (list_node_t *node);
+
+/**
+ * Return the first node.
+ * \param list the list
+ * \return the first node
+ */
+list_node_t *
+list_begin (list_t *list);
+
+/**
+ * Return past the last node.
+ * \param list the list
+ * \return the node after the last
+ */
+list_node_t *
+list_end (list_t *list);
+
+/**
+ * Return last node to backward iteration.
+ * \param list the list
+ * \return the last node
+ */
+list_node_t *
+list_rbegin (list_t *list);
+
+/**
+ * Return before the first node.
+ * \param list the list
+ * \return the node before the first
+ */
+list_node_t *
+list_rend (list_t *list);
+
+/**
+ * Return the next node.
+ * \param node the current node
+ * \return the node after the current one
+ */
+list_node_t *
+list_next (list_node_t *node);
+
+/**
+ * Return the previous node.
+ * \param node the current node
+ * \return the node before the current one
+ */
+list_node_t *
+list_prev (list_node_t *node);
+
+/**
+ * Is the list empty?
+ * \param list the list
+ * \return true if empty
+ */
+bool
+list_empty (list_t *list);
+
+/**
+ * Push a node to the end of a list.
+ * \param list the list
+ * \param node the node to push
+ */
+void
+list_push (list_t *list, list_node_t *node);
+
+/**
+ * Unshift a node to the begin of a list.
+ * \param list the list
+ * \param node the node to unshift
+ */
+void
+list_unshift (list_t *list, list_node_t *node);
+
+/**
+ * Pop a node from the end of a list.
+ * \param list the list
+ * \return the popped node
+ */
+list_node_t *
+list_pop (list_t *list);
+
+/**
+ * Shift a node from the begin of a list.
+ * \param list the list
+ * \return the shifted node
+ */
+list_node_t *
+list_shift (list_t *list);
+
+/**
+ * Remove a node from a list.
+ * \param list the list
+ * \param node the node to remove
+ */
+void
+list_remove (list_t *list, list_node_t *node);
+
+/**
+ * Insert a node into a list.
+ * \param list the list
+ * \param before node before which to insert
+ * \param node node to insert
+ */
+void
+list_insert (list_t *list, list_node_t *before, list_node_t *node);
+
+/**
+ * Push a range [first, last) to a end of a list.
+ * \param to list to push to
+ * \param from list to remove from
+ * \param first first node to push
+ * \param last node after the last one to push
+ */
+void
+list_push_range (list_t *to, list_t *from,
+ list_node_t *first, list_node_t *last);
+
+/**
+ * Unshift a range [first, last) to a begin of a list.
+ * \param to list to unshift to
+ * \param from list to remove from
+ * \param first first node to unshift
+ * \param last node after the last one to unshift
+ */
+void
+list_unshift_range (list_t *to, list_t *from,
+ list_node_t *first, list_node_t *last);
+
+/**
+ * Insert a range [first, last) to a list
+ * \param to list to insert to
+ * \param from list to remove from
+ * \param before node before which to insert
+ * \param first first node to insert
+ * \param last node after the last one to insert
+ */
+void
+list_insert_range (list_t *to, list_t *from, list_node_t *before,
+ list_node_t *first, list_node_t *last);
+
+END_DECLS
+
+#endif /* lib_list_h */