Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
|
A doubly-linked list that can be traversed in either direction. More...
#include <linked_list.h>
Public Member Functions | |
LinkedList * | AllocateLinkedList (void(*free_node_fn_p)(ListItem *const node_p)) |
Create a new LinkedList. More... | |
void | FreeLinkedList (LinkedList *const list_p) |
Free a LinkedList. More... | |
void | InitLinkedList (LinkedList *const list_p) |
Initialise/clear a LinkedList to be empty. More... | |
void | LinkedListAddHead (LinkedList *const list_p, ListItem *const node_p) |
Add a ListItem to the start of a LinkedList. More... | |
void | LinkedListAddTail (LinkedList *const list_p, ListItem *const node_p) |
Add a ListItem to the end of a LinkedList. More... | |
ListItem * | LinkedListRemHead (LinkedList *const list_p) |
Remove the first ListItem from a LinkedList. More... | |
ListItem * | LinkedListRemTail (LinkedList *const list_p) |
Remove the last ListItem from a LinkedList. More... | |
void | LinkedListRemove (LinkedList *const list_p, ListItem *const node_p) |
Remove a ListItem from a LinkedList. More... | |
bool | LinkedListSort (LinkedList *const list_p, int(*compare_nodes_fn)(const void *v1_p, const void *v2_p)) |
Sort a LinkedList. More... | |
void | SetLinkedListFreeNodeFunction (LinkedList *const list_p, void(*free_node_fn)(ListItem *const node_p)) |
Set the function used to free ListsNodes when the LinkedList is freed. More... | |
void | LinkedListPrioritisedInsert (LinkedList *const list_p, ListItem *const node_p, int(*compare_nodes_fn)(const void *v1_p, const void *v2_p)) |
Insert a node into a list using the given sorting algorithm to determine the node's position on the list. More... | |
void | LinkedListInsert (LinkedList *const list_p, ListItem *const prev_node_p, ListItem *const node_to_insert_p) |
Insert a node into a list after a given node. More... | |
ListItem * | LinkedListBinarySearch (const LinkedList *const list_p, const ListItem *const node_p, int(*compare_nodes_fn)(const void *v1_p, const void *v2_p), int *const index_p) |
Search a sorted list using the given sorting algorithm for a given node. More... | |
void | MoveListContents (LinkedList *const src_list_p, LinkedList *const dest_list_p) |
Move the contents of one list to another. More... | |
LinkedList * | SplitList (LinkedList *const list_p, const uint32 split_list_head_index) |
Cut a list into two lists at the given index. More... | |
void | ClearLinkedList (LinkedList *const list_p) |
Empty a LinkedList by freeing all of its ListItems. More... | |
void | InitListItem (ListItem *const item_p) |
Initialise a ListItem. More... | |
Data Fields | |
ListItem * | ll_head_p |
A pointer to the first ListItem on this list. More... | |
ListItem * | ll_tail_p |
A pointer to the last ListItem on this list. More... | |
uint32 | ll_size |
The number of ListItems on this list. More... | |
void(* | ll_free_node_fn_p )(ListItem *node_p) |
Callback function to use when freeing a ListItem. More... | |
A doubly-linked list that can be traversed in either direction.
LinkedList * AllocateLinkedList | ( | void(*)(ListItem *const node_p) | free_node_fn_p | ) |
Create a new LinkedList.
The new LinkedList is initialised as an empty list.
free_node_fn_p | The callback function to use when freeing ListItems. If this isn't set the default is to call free (). |
void FreeLinkedList | ( | LinkedList *const | list_p | ) |
Free a LinkedList.
Each node is passed to the list's ll_free_node_fn_p or stdlib's free if ll_free_node_fn_p is NULL to be freed. Then the LinkedList is also freed
list_p | The LinkedList to free. |
void InitLinkedList | ( | LinkedList *const | list_p | ) |
Initialise/clear a LinkedList to be empty.
list_p | The LinkedList to initialise. |
void LinkedListAddHead | ( | LinkedList *const | list_p, |
ListItem *const | node_p | ||
) |
Add a ListItem to the start of a LinkedList.
list_p | The LinkedList to add the ListItem to. |
node_p | The ListItem to add. |
void LinkedListAddTail | ( | LinkedList *const | list_p, |
ListItem *const | node_p | ||
) |
Add a ListItem to the end of a LinkedList.
list_p | The LinkedList to add the ListItem to. |
node_p | The ListItem to add. |
ListItem * LinkedListRemHead | ( | LinkedList *const | list_p | ) |
Remove the first ListItem from a LinkedList.
list_p | The LinkedList to remove the first ListItem from. |
ListItem * LinkedListRemTail | ( | LinkedList *const | list_p | ) |
Remove the last ListItem from a LinkedList.
list_p | The LinkedList to remove the last ListItem from. |
void LinkedListRemove | ( | LinkedList *const | list_p, |
ListItem *const | node_p | ||
) |
Remove a ListItem from a LinkedList.
list_p | The LinkedList to remove the ListItem from. |
node_p | The ListItem to be removed. |
bool LinkedListSort | ( | LinkedList *const | list_p, |
int(*)(const void *v1_p, const void *v2_p) | compare_nodes_fn | ||
) |
Sort a LinkedList.
list_p | The LinkedList to sort. |
compare_nodes_fn | Function used to sort the ListItems. |
void SetLinkedListFreeNodeFunction | ( | LinkedList *const | list_p, |
void(*)(ListItem *const node_p) | free_node_fn | ||
) |
Set the function used to free ListsNodes when the LinkedList is freed.
list_p | The LinkedList to set the function for. |
free_node_fn | The function that will be used to free the ListItems. |
void LinkedListPrioritisedInsert | ( | LinkedList *const | list_p, |
ListItem *const | node_p, | ||
int(*)(const void *v1_p, const void *v2_p) | compare_nodes_fn | ||
) |
Insert a node into a list using the given sorting algorithm to determine the node's position on the list.
list_p | The LinkedList to insert the node on. |
node_p | The ListItem to insert into the list. |
compare_nodes_fn | Function used to compare the ListItems. |
void LinkedListInsert | ( | LinkedList *const | list_p, |
ListItem *const | prev_node_p, | ||
ListItem *const | node_to_insert_p | ||
) |
Insert a node into a list after a given node.
list_p | The LinkedList to insert the node on. |
prev_node_p | The ListItem to insert our new node directly after. If this NULL, then our node will be inserted at the start of the list. |
node_to_insert_p | The ListItem to insert on the list. |
ListItem * LinkedListBinarySearch | ( | const LinkedList *const | list_p, |
const ListItem *const | node_p, | ||
int(*)(const void *v1_p, const void *v2_p) | compare_nodes_fn, | ||
int *const | index_p | ||
) |
Search a sorted list using the given sorting algorithm for a given node.
list_p | The LinkedList to search. |
node_p | The ListItem to search for. |
compare_nodes_fn | Function used to compare the ListItems. |
index_p | Address where the index of the matching item will be stored if it is found. |
NULL
if it could not be found on the LinkedList. void MoveListContents | ( | LinkedList *const | src_list_p, |
LinkedList *const | dest_list_p | ||
) |
Move the contents of one list to another.
This function is the equivalent of a "cut and paste" of all of the nodes from one list to another. The nodes are appended to the end of the destination list in the same order in which they appeared in the source list which is then left empty.
src_list_p | The LinkedList to remove all of the nodes from. |
dest_list_p | The LinkedList to which the nodes will be appended. |
LinkedList * SplitList | ( | LinkedList *const | list_p, |
const uint32 | split_list_head_index | ||
) |
Cut a list into two lists at the given index.
list_p | The LinkedList to split. |
split_list_head_index | The index of the ListItem that will be the first ListItem on the newly created list, i.e. its ll_head_p. |
void ClearLinkedList | ( | LinkedList *const | list_p | ) |
Empty a LinkedList by freeing all of its ListItems.
list_p | The LinkedList to empty. |
void InitListItem | ( | ListItem *const | item_p | ) |
uint32 ll_size |
The number of ListItems on this list.