libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_linked_list.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblLinkedListNode structure and related functions
3 * \ingroup containers
4 * \todo
5 * - GblLinkedList_insert(): insert into middle by index
6 * - GblLinkedList_insertAfter(): no list head required
7 * - Slick KOS/BSD-style macro for() looping over nodes
8 *
9 * \author Falco Girgis
10 */
11
12#ifndef GIMBAL_LINKED_LIST_H
13#define GIMBAL_LINKED_LIST_H
14
15#include "../core/gimbal_decls.h"
16
17#define GBL_LINKED_LIST_NPOS GBL_NPOS
18#define GBL_LINKED_LIST_NODE_INITIALIZER() { .pNext = NULL }
19#define GBL_LINKED_LIST_NODE(name) GblLinkedListNode name = { .pNext = &name }
20#define GBL_LINKED_LIST_ENTRY(node, structure, field) GBL_CONTAINER_OF(node, structure, field)
21
22#define GBL_SELF_TYPE GblLinkedListNode
23
24typedef int (*GblLinkedListCmpFn)(const void* pA, const void* pb, void* pClosure);
25
27
28/*! \brief Intrustive singly linked list structure with vector-style API
29 * \ingroup containers
30 */
31typedef struct GblLinkedListNode {
32 struct GblLinkedListNode* pNext;
33} GblLinkedListNode;
34
35GBL_EXPORT void GblLinkedList_init (GBL_SELF) GBL_NOEXCEPT;
36GBL_EXPORT void GblLinkedList_move (GBL_SELF, GBL_SELF_TYPE* pHead) GBL_NOEXCEPT;
37
38GBL_EXPORT GblBool GblLinkedList_empty (GBL_CSELF) GBL_NOEXCEPT;
39GBL_EXPORT size_t GblLinkedList_count (GBL_CSELF) GBL_NOEXCEPT;
40
41GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_at (GBL_CSELF, size_t index) GBL_NOEXCEPT;
42GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_front (GBL_CSELF) GBL_NOEXCEPT;
44GBL_EXPORT GblBool GblLinkedList_contains (GBL_CSELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
45GBL_EXPORT size_t GblLinkedList_find (GBL_CSELF, GBL_SELF_TYPE* PNode) GBL_NOEXCEPT;
46GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_middle (GBL_CSELF) GBL_NOEXCEPT;
47GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_beforeMiddle (GBL_CSELF) GBL_NOEXCEPT;
48
49GBL_EXPORT void GblLinkedList_pushBack (GBL_SELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
50GBL_EXPORT void GblLinkedList_pushFront (GBL_SELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
51GBL_EXPORT void GblLinkedList_moveBack (GBL_SELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
52GBL_EXPORT void GblLinkedList_moveFront (GBL_SELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
53GBL_EXPORT void GblLinkedList_joinBack (GBL_SELF, GBL_SELF_TYPE* pList) GBL_NOEXCEPT;
54GBL_EXPORT void GblLinkedList_joinFront (GBL_SELF, GBL_SELF_TYPE* pList) GBL_NOEXCEPT;
55GBL_EXPORT void GblLinkedList_joinSorted (GBL_SELF,
56 GBL_SELF_TYPE* pList,
57 GblLinkedListCmpFn pCmpFn,
58 void* pCl) GBL_NOEXCEPT;
59
60GBL_EXPORT GblBool GblLinkedList_insert (GBL_SELF, GBL_SELF_TYPE* pNode, size_t index) GBL_NOEXCEPT;
61GBL_EXPORT void GblLinkedList_insertAfter (GBL_SELF_TYPE* pNode1, GBL_SELF_TYPE* pNode2) GBL_NOEXCEPT;
62
63GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_popBack (GBL_SELF) GBL_NOEXCEPT;
64GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_popFront (GBL_SELF) GBL_NOEXCEPT;
65
66GBL_EXPORT GblBool GblLinkedList_swap (GBL_SELF, GBL_SELF_TYPE* pNode1, GBL_SELF_TYPE* pNode2) GBL_NOEXCEPT;
67GBL_EXPORT GblBool GblLinkedList_remove (GBL_SELF, GBL_SELF_TYPE* pNode) GBL_NOEXCEPT;
68GBL_EXPORT GblBool GblLinkedList_replace (GBL_SELF, GBL_SELF_TYPE* pNode1, GBL_SELF_TYPE* pNode2) GBL_NOEXCEPT;
69GBL_EXPORT void GblLinkedList_splitAfter (GBL_SELF, GBL_SELF_TYPE* pHead2, GBL_SELF_TYPE* pAfter) GBL_NOEXCEPT;
70
71GBL_EXPORT GBL_SELF_TYPE* GblLinkedList_erase (GBL_SELF, size_t index) GBL_NOEXCEPT;
72GBL_EXPORT void GblLinkedList_clear (GBL_SELF) GBL_NOEXCEPT;
73
74GBL_EXPORT void GblLinkedList_mergeSort (GBL_SELF, GblLinkedListCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
75
76GBL_EXPORT void GblLinkedList_reverse (GBL_SELF) GBL_NOEXCEPT;
77
79
80#undef GBL_SELF_TYPE
81
82#endif // GIMBAL_LINKED_LIST_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_CONTAINER_OF(ptr, type, member)
#define GBL_SELF_TYPE
Definition gimbal_md5.h:22
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
#define GBL_NPOS
Intrustive singly linked list structure with vector-style API.