src/linked_list.c File Reference

Generic doubly linked list. More...

Data Structures

struct  ll_node_tag
struct  ll_list_tag

Functions

ll_list_sll_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_sll_insert (ll_list_s *list, void *data, ll_node_s *after)
 Insert a new item into the linked list.
ll_node_sll_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_sll_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_sll_get_prev_node (const ll_node_s *node)
 Get the previous node from the given node.
ll_node_sll_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.

Detailed Description

Generic doubly linked list.

Date:
1 Jan 2010
Author:
Zachary Sims <zacs7@users.sourceforge.net>

Module prefix: ll_

$Id$


Function Documentation

ll_list_s* ll_create_list ( void(*)(void *)  onfree  ) 

Creates a new linked list with no items.

Warning:
The onfree function will be called per item in the list. Be cautious of double-frees.
See also:
ll_free_list()
Parameters:
onfree The function to call when items are removed from the list. May not be NULL.
Returns:
On success non-NULL. On error, NULL is returned.
bool ll_delete ( ll_list_s list,
ll_node_s node 
)

Deletes the given node from the linked list.

The registered onfree callback when the list was created is called.

Warning:
Deleting nodes that other functions may have as 'interators' could cause segfaults.
Parameters:
list The list to search in.
node The node to remove.
Returns:
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.

Parameters:
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.
Returns:
The node if it's found. Otherwise NULL is returned.
void ll_free_list ( ll_list_s list  ) 

Frees the given linked list and all of its items.

Parameters:
list The list to free. The list will no longer be valid after this function returns.
See also:
ll_create_list()
ll_node_s* ll_get_head_node ( const ll_list_s list  ) 

Returns the node at the front of the list.

Inserting or deleting may invalidate the return value.

Parameters:
list The list to return the head node from.
Returns:
The head of the list. NULL if there is no head node.
ll_node_s* ll_get_next_node ( const ll_node_s node  ) 

Get the next node from the given node.

Parameters:
node The current node.
Returns:
The next node from the given 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.

Parameters:
node The node to return the data from.
Returns:
The data contained in the node.
size_t ll_get_number_items ( const ll_list_s list  ) 

Return the number of items in the list.

Parameters:
list The list to return the number of items of.
Returns:
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.

Parameters:
node The current node.
Returns:
The previous node from the given node. NULL if there is no previous node.
ll_node_s* ll_insert ( ll_list_s list,
void *  data,
ll_node_s after 
)

Insert a new item into the linked list.

The item will be inserted after the given node.

Parameters:
list The list to insert the node into.
data The data to store.
after The node to insert the item after, NULL for head.
Returns:
the inserted node if the item was inserted. On error, 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.

Parameters:
node The node to set the data of.
data The new data.
Returns:
The old data contained in the node.

Generated by  doxygen 1.6.2