Generic doubly linked list. More...
Data Structures | |
struct | ll_node_tag |
struct | ll_list_tag |
Functions | |
ll_list_s * | ll_create_list (void(*onfree)(void *)) |
Creates a new linked list with no items. | |
void | ll_free_list (ll_list_s *list) |
Frees the given linked list and all of its items. | |
ll_node_s * | ll_insert (ll_list_s *list, void *data, ll_node_s *after) |
Insert a new item into the linked list. | |
ll_node_s * | ll_find (ll_list_s *list, void *data, bool(*compare)(void *, void *), ll_node_s *start) |
Searches for an item in the linked list. | |
bool | ll_delete (ll_list_s *list, ll_node_s *node) |
Deletes the given node from the linked list. | |
ll_node_s * | ll_get_next_node (const ll_node_s *node) |
Get the next node from the given node. | |
size_t | ll_get_number_items (const ll_list_s *list) |
Return the number of items in the list. | |
ll_node_s * | ll_get_prev_node (const ll_node_s *node) |
Get the previous node from the given node. | |
ll_node_s * | ll_get_head_node (const ll_list_s *list) |
Returns the node at the front of the list. | |
void * | ll_get_node_data (const ll_node_s *node) |
Returns the data contained in the given node. | |
void * | ll_set_node_data (ll_node_s *node, void *data) |
Sets the data of the given node. |
Generic doubly linked list.
Module prefix: ll_
$Id$
ll_list_s* ll_create_list | ( | void(*)(void *) | onfree | ) |
Creates a new linked list with no items.
onfree | The function to call when items are removed from the list. May not be NULL. |
NULL
is returned. Deletes the given node from the linked list.
The registered onfree callback when the list was created is called.
list | The list to search in. | |
node | The node to remove. |
true
if the node was deleted. On error, false
is returned. ll_node_s* ll_find | ( | ll_list_s * | list, | |
void * | data, | |||
bool(*)(void *, void *) | compare, | |||
ll_node_s * | start | |||
) |
Searches for an item in the linked list.
The first item for which compare returns true
for is returned.
list | The list to search in. | |
data | The item to search for. | |
compare | The callback function used to compare items. The compare function is called with the given item as the first argument. | |
start | The node to start searching from. NULL for the start of the list. |
NULL
is returned. void ll_free_list | ( | ll_list_s * | list | ) |
Frees the given linked list and all of its items.
list | The list to free. The list will no longer be valid after this function returns. |
Returns the node at the front of the list.
Inserting or deleting may invalidate the return value.
list | The list to return the head node from. |
NULL
if there is no head node. Get the next node from the given node.
node | The current node. |
NULL
if there is no next node. void* ll_get_node_data | ( | const ll_node_s * | node | ) |
Returns the data contained in the given node.
node | The node to return the data from. |
size_t ll_get_number_items | ( | const ll_list_s * | list | ) |
Return the number of items in the list.
list | The list to return the number of items of. |
Get the previous node from the given node.
node | The current node. |
NULL
if there is no previous node. Insert a new item into the linked list.
The item will be inserted after the given node.
list | The list to insert the node into. | |
data | The data to store. | |
after | The node to insert the item after, NULL for head. |
NULL
is returned. void* ll_set_node_data | ( | ll_node_s * | node, | |
void * | data | |||
) |
Sets the data of the given node.
This is useful if you insert duplicate pointers into the list, but don't want to double free.
node | The node to set the data of. | |
data | The new data. |