*/
-// com_list.c - generic doubly linked list interface, inspired by Linux list.h
+// com_list.c - generic doubly linked list interface, adapted from Linux list.h
#include "qtypes.h"
#include "com_list.h"
+/*
+ * Creates a new linked list. Initializes the head to point to itself.
+ * If it's a list header, the result is an empty list.
+ */
+void List_Create(llist_t *list)
+{
+ list->next = list->prev = NULL;
+}
+
/*
* Insert a node between two known nodes.
*
/*
* Bridge prev and next together, when removing the parent of them.
*/
-static void __List_Delete(llist_t *prev, llist_t *next)
+static inline void __List_Delete(llist_t *prev, llist_t *next)
{
next->prev = prev;
prev->next = next;
/*
* Redundant?
*/
-static void __List_Delete_Node(llist_t *node)
+static inline void __List_Delete_Node(llist_t *node)
{
__List_Delete(node->prev, node->next);
}
old->next = old->prev = old;
}
+/*
+ * Replace old with new. Initialize old.
+ * Old is overwritten if empty.
+ */
+void List_Replace_Init(llist_t *old, llist_t *_new)
+{
+ List_Replace(old, _new);
+ List_Create(old);
+}
+
/*
* Swap node1 with node2 in place.
*/
{
llist_t *first;
- if (!List_IsEmpty(head))
+ if (!List_Is_Empty(head))
{
first = head->next;
List_Move_Tail(first, head);
/*
* Concatenate two lists. The head of list will be discarded.
*/
-static void __List_Splice(const llist_t *list, llist_t *prev, llist_t *next)
+static inline void __List_Splice(const llist_t *list, llist_t *prev, llist_t *next)
{
llist_t *first = list->next;
llist_t *last = list->prev;
*/
void List_Splice(const llist_t *list, llist_t *head)
{
- if(!List_IsEmpty(list))
+ if(!List_Is_Empty(list))
__List_Splice(list, head, head->next);
}
*/
void List_Splice_Tail(const llist_t *list, llist_t *head)
{
- if (!List_IsEmpty(list))
+ if (!List_Is_Empty(list))
__List_Splice(list, head->prev, head);
}
-qboolean List_IsFirst(llist_t *list, llist_t *start)
+qbool List_Is_First(llist_t *list, llist_t *start)
{
return list->prev == start;
}
-qboolean List_IsLast(llist_t *list, llist_t *start)
+qbool List_Is_Last(llist_t *list, llist_t *start)
{
return list->next == start;
}
-qboolean List_IsEmpty(const llist_t *list)
+qbool List_Is_Empty(const llist_t *list)
{
return list->next == list;
-}
\ No newline at end of file
+}