Manage a linked list (for internal use only). More...
#include "LinkedList.hpp"
Go to the source code of this file.
Functions | |
int | ListInit (LinkedList *list, cmp_routine cmp_func, free_function free_func) |
Initializes LinkedList. Must be called first and only once for List. | |
ListNode * | ListAddHead (LinkedList *list, void *item) |
Adds a node to the head of the list. Node gets immediately after list head. | |
ListNode * | ListAddTail (LinkedList *list, void *item) |
Adds a node to the tail of the list. Node gets added immediately before list.tail. | |
ListNode * | ListAddAfter (LinkedList *list, void *item, ListNode *bnode) |
Adds a node after the specified node. Node gets added immediately after bnode. | |
ListNode * | ListAddBefore (LinkedList *list, void *item, ListNode *anode) |
Adds a node before the specified node. Node gets added immediately before anode. | |
void * | ListDelNode (LinkedList *list, ListNode *dnode, int freeItem) |
Removes a node from the list. The memory for the node is freed. | |
int | ListDestroy (LinkedList *list, int freeItem) |
Removes all memory associated with list nodes. Does not free LinkedList *list. | |
ListNode * | ListHead (LinkedList *list) |
Returns the head of the list. | |
ListNode * | ListTail (LinkedList *list) |
Returns the tail of the list. | |
ListNode * | ListNext (LinkedList *list, ListNode *node) |
Returns the next item in the list. | |
ListNode * | ListPrev (LinkedList *list, ListNode *node) |
Returns the previous item in the list. | |
ListNode * | ListFind (LinkedList *list, ListNode *start, void *item) |
Finds the specified item in the list. | |
long | ListSize (LinkedList *list) |
Returns the size of the list. | |
Scope restricted to file | |
int | anonymous_namespace{LinkedList.cpp}::freeListNode (ListNode *node, LinkedList *list) |
Free list node. | |
ListNode * | anonymous_namespace{LinkedList.cpp}::CreateListNode (void *item, LinkedList *list) |
Dynamically creates a list node. | |
Variables | |
constexpr int | FREELISTSIZE {100} |
Size of a free list. | |
Manage a linked list (for internal use only).
Because this is for internal use, parameters are NOT checked for validity. The caller must ensure valid parameters.
Definition in file LinkedList.cpp.
int ListInit | ( | LinkedList * | list, |
cmp_routine | cmp_func, | ||
free_function | free_func | ||
) |
Initializes LinkedList. Must be called first and only once for List.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | cmp_func | Function used to compare items. (May be NULL). |
[in] | free_func | Function used to free items. (May be NULL). |
Definition at line 95 of file LinkedList.cpp.
ListNode * ListAddHead | ( | LinkedList * | list, |
void * | item | ||
) |
Adds a node to the head of the list. Node gets immediately after list head.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | item | Item to be added. |
Definition at line 119 of file LinkedList.cpp.
ListNode * ListAddTail | ( | LinkedList * | list, |
void * | item | ||
) |
Adds a node to the tail of the list. Node gets added immediately before list.tail.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | item | Item to be added. |
Definition at line 128 of file LinkedList.cpp.
ListNode * ListAddAfter | ( | LinkedList * | list, |
void * | item, | ||
ListNode * | bnode | ||
) |
Adds a node after the specified node. Node gets added immediately after bnode.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | item | Item to be added. |
[in] | bnode | Node to add after. |
Definition at line 137 of file LinkedList.cpp.
ListNode * ListAddBefore | ( | LinkedList * | list, |
void * | item, | ||
ListNode * | anode | ||
) |
Adds a node before the specified node. Node gets added immediately before anode.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | item | Item to be added. |
[in] | anode | Node to add in front of. |
Definition at line 160 of file LinkedList.cpp.
void * ListDelNode | ( | LinkedList * | list, |
ListNode * | dnode, | ||
int | freeItem | ||
) |
Removes a node from the list. The memory for the node is freed.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | dnode | Node to delete. |
[in] | freeItem | if !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed. |
Definition at line 183 of file LinkedList.cpp.
int ListDestroy | ( | LinkedList * | list, |
int | freeItem | ||
) |
Removes all memory associated with list nodes. Does not free LinkedList *list.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | freeItem | If !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed. |
Definition at line 205 of file LinkedList.cpp.
ListNode * ListHead | ( | LinkedList * | list | ) |
Returns the head of the list.
Precondition: The list has been initialized.
list | [0] Must be valid, non null, pointer to a linked list. |
Definition at line 223 of file LinkedList.cpp.
ListNode * ListTail | ( | LinkedList * | list | ) |
Returns the tail of the list.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
Definition at line 235 of file LinkedList.cpp.
ListNode * ListNext | ( | LinkedList * | list, |
ListNode * | node | ||
) |
Returns the next item in the list.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | node | Node from the list. |
Definition at line 247 of file LinkedList.cpp.
ListNode * ListPrev | ( | LinkedList * | list, |
ListNode * | node | ||
) |
Returns the previous item in the list.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | node | Node from the list. |
Definition at line 259 of file LinkedList.cpp.
ListNode * ListFind | ( | LinkedList * | list, |
ListNode * | start, | ||
void * | item | ||
) |
Finds the specified item in the list.
Uses the compare function specified in ListInit. If compare function is nullptr then compares items as pointers.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
[in] | start | The node to start from, nullptr if to start from beginning. |
[in] | item | The item to search for. |
Definition at line 272 of file LinkedList.cpp.
long ListSize | ( | LinkedList * | list | ) |
Returns the size of the list.
Precondition: The list has been initialized.
[in] | list | Must be valid, non null, pointer to a linked list. |
Definition at line 300 of file LinkedList.cpp.
|
constexpr |
Size of a free list.
Definition at line 46 of file LinkedList.cpp.