include/razorback/list.h File Reference

Linked list functions. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <razorback/visibility.h>
#include <razorback/lock.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ListNode
 List node structure. More...
struct  List
 List structure. More...

Defines

#define LIST_MODE_GENERIC   0
 List modes.
#define LIST_MODE_STACK   1
 Stack list.
#define LIST_MODE_QUEUE   2
 Queue list.

#define LIST_EACH_OK   0
 List iteration returns.
#define LIST_EACH_ERROR   1
 Error processing node.
#define LIST_EACH_REMOVE   2
 Node successfully processed, remove from list.

Functions

SO_PUBLIC struct ListList_Create (int mode, int(*cmp)(void *, void *), int(*keyCmp)(void *, void *), void(*destroy)(void *), void *(*clone)(void *), void(*nodeLock)(void *), void(*nodeUnlock)(void *))
 Create a new List.
SO_PUBLIC bool List_Push (struct List *list, void *item)
 Add an item to a List.
SO_PUBLIC void * List_Pop (struct List *list)
 Remove the next item from a List.
SO_PUBLIC void List_Remove (struct List *list, void *item)
 Remove the item from the list.
SO_PUBLIC void * List_Find (struct List *list, void *id)
 Search a list for the item by key.
SO_PUBLIC bool List_ForEach (struct List *list, int(*op)(void *i, void *ud), void *userData)
 Iterate all items in a list executing op for each node.
SO_PUBLIC size_t List_Length (struct List *list)
 Get the number of items in a List in a thread safe fashion.
SO_PUBLIC void List_Clear (struct List *list)
 Remove all items from a List.
SO_PUBLIC void List_Lock (struct List *list)
 Lock a list.
SO_PUBLIC void List_Unlock (struct List *list)
 Unlock a list.
SO_PUBLIC void List_Destroy (struct List *list)
 Destroy a List.
SO_PUBLIC struct ListList_Clone (struct List *source)
 Clone a list and its contents.

Detailed Description

Linked list functions.


Define Documentation

#define LIST_EACH_OK   0

List iteration returns.

Node successfully processed

#define LIST_EACH_REMOVE   2

Node successfully processed, remove from list.

#define LIST_MODE_GENERIC   0

List modes.

Generic list


Function Documentation

SO_PUBLIC void List_Clear ( struct List list  ) 

Remove all items from a List.

Parameters:
list The List to clear.
SO_PUBLIC struct List* List_Clone ( struct List source  )  [read]

Clone a list and its contents.

Note:
The list must have been created with a none NULL clone function pointer.
Parameters:
list The List to clone.
Returns:
A new list on success, NULL on error.
SO_PUBLIC struct List* List_Create ( int  mode,
int(*)(void *, void *)  cmp,
int(*)(void *, void *)  keyCmp,
void(*)(void *)  destroy,
void *(*)(void *)  clone,
void(*)(void *)  nodeLock,
void(*)(void *)  nodeUnlock 
) [read]

Create a new List.

Parameters:
mode The list operation mode
cmp Function pointer to the node comparator.
keyCmp Function pointer to the node key comparator.
destroy Function pointer to the node data destructor.
clone Function pointer to the node clone routine. (Optional - Use NULL if cloning is not supported)
nodeLock Function pointer to the node lock routine. (Optional - Use NULL if node locking is not required)
nodeUnlock Function pointer to the node unlock routine. (Optional - Use NULL if node locking is not required)
Returns:
A new List on success, NULL on error.
SO_PUBLIC void List_Destroy ( struct List list  ) 

Destroy a List.

Parameters:
list The List to destroy.
SO_PUBLIC void* List_Find ( struct List list,
void *  id 
)

Search a list for the item by key.

Parameters:
list The List to search.
id The node key.
Returns:
A pointer to the item if found, NULL if not.
SO_PUBLIC bool List_ForEach ( struct List list,
int(*)(void *i, void *ud)  op,
void *  userData 
)

Iterate all items in a list executing op for each node.

Parameters:
list The List to iterate.
op Function pointer to the routine to run on every node. Op should return on of the list iteration status.
userData User data to pass as the ud argument to op.
Returns:
true on success, false on error.
SO_PUBLIC size_t List_Length ( struct List list  ) 

Get the number of items in a List in a thread safe fashion.

Parameters:
list The list to get the size of
Returns:
The number of items in the list.
SO_PUBLIC void List_Lock ( struct List list  ) 

Lock a list.

Parameters:
list The List to lock.
Returns:
true on success, false on error
SO_PUBLIC void* List_Pop ( struct List list  ) 

Remove the next item from a List.

Note:
For a list in queue or stack mode, this function will block until an item is available. In gerneral mode NULL will be returned if there is item to remove.
Parameters:
list The List to remove the item from.
Returns:
A pointer to the removed item on success, NULL on failure.
SO_PUBLIC bool List_Push ( struct List list,
void *  item 
)

Add an item to a List.

Parameters:
list The List to add the item to.
item The item to add.
Returns:
true on success, false on error.
SO_PUBLIC void List_Remove ( struct List list,
void *  item 
)

Remove the item from the list.

Parameters:
list The List to remove the item from.
item The item to remove.
SO_PUBLIC void List_Unlock ( struct List list  ) 

Unlock a list.

Parameters:
list The List to unlock.
Returns:
true on success, false on error.
 All Data Structures Files Functions Variables Enumerations Enumerator Defines
Generated on Sun Dec 9 04:00:11 2012 for RazorbackAPI by  doxygen 1.6.3