libUPnP 1.14.19
Data Structures | Macros | Typedefs | Functions
LinkedList.h File Reference
#include "FreeList.h"
Include dependency graph for LinkedList.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LISTNODE
 
struct  LINKEDLIST
 

Macros

#define EOUTOFMEM   (-7 & 1 << 29)
 
#define FREELISTSIZE   100
 
#define LIST_SUCCESS   1
 
#define LIST_FAIL   0
 

Typedefs

typedef void(* free_function) (void *arg)
 
typedef int(* cmp_routine) (void *itemA, void *itemB)
 
typedef struct LISTNODE ListNode
 
typedef struct LINKEDLIST LinkedList
 

Functions

int ListInit (LinkedList *list, cmp_routine cmp_func, free_function free_func)
 Initializes LinkedList. Must be called first and only once for List.
 
ListNodeListAddHead (LinkedList *list, void *item)
 Adds a node to the head of the list. Node gets immediately after list head.
 
ListNodeListAddTail (LinkedList *list, void *item)
 Adds a node to the tail of the list. Node gets added immediately before list.tail.
 
ListNodeListAddAfter (LinkedList *list, void *item, ListNode *bnode)
 Adds a node after the specified node. Node gets added immediately after bnode.
 
ListNodeListAddBefore (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.
 
ListNodeListHead (LinkedList *list)
 Returns the head of the list.
 
ListNodeListTail (LinkedList *list)
 Returns the tail of the list.
 
ListNodeListNext (LinkedList *list, ListNode *node)
 Returns the next item in the list.
 
ListNodeListPrev (LinkedList *list, ListNode *node)
 Returns the previous item in the list.
 
ListNodeListFind (LinkedList *list, ListNode *start, void *item)
 Finds the specified item in the list.
 
long ListSize (LinkedList *list)
 Returns the size of the list.
 

Typedef Documentation

◆ cmp_routine

typedef int(* cmp_routine) (void *itemA, void *itemB)

Function for comparing list items. Returns 1 if itemA==itemB

◆ free_function

typedef void(* free_function) (void *arg)

Function for freeing list items.

◆ LinkedList

typedef struct LINKEDLIST LinkedList

Linked list (no protection).

Because this is for internal use, parameters are NOT checked for validity. The first item of the list is stored at node: head->next The last item of the list is stored at node: tail->prev If head->next=tail, then list is empty. To iterate through the list:

 LinkedList g;
 ListNode *temp = NULL;
 for (temp = ListHead(g);temp!=NULL;temp = ListNext(g,temp)) {
 }

◆ ListNode

typedef struct LISTNODE ListNode

Linked list node. Stores generic item and pointers to next and prev.

Function Documentation

◆ ListAddAfter()

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.

Returns
The pointer to the ListNode on success, NULL on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
itemItem to be added.
bnodeNode to add after.

References LINKEDLIST::size.

◆ ListAddBefore()

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.

Returns
The pointer to the ListNode on success, NULL on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
itemItem to be added.
anodeNode to add in front of.

References LINKEDLIST::size.

◆ ListAddHead()

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.

Returns
The pointer to the ListNode on success, NULL on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
itemItem to be added.

References LINKEDLIST::head.

◆ ListAddTail()

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.

Returns
The pointer to the ListNode on success, NULL on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
itemItem to be added.

References LINKEDLIST::tail.

◆ ListDelNode()

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.

Returns
The pointer to the item stored in the node or NULL if the item is freed.
Parameters
listMust be valid, non null, pointer to a linked list.
dnodeNode to delete.
freeItemif !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed.

References LINKEDLIST::free_func, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.

◆ ListDestroy()

int ListDestroy ( LinkedList list,
int  freeItem 
)

Removes all memory associated with list nodes. Does not free LinkedList *list.

Precondition: The list has been initialized.

Returns
0 on success, EINVAL on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
freeItemif !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed.

References LINKEDLIST::freeNodeList, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.

◆ ListFind()

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 NULL then compares items as pointers.

Precondition: The list has been initialized.

Returns
The node containing the item. NULL if no node contains the item.
Parameters
listMust be valid, non null, pointer to a linked list.
startThe node to start from, NULL if to start from beginning.
itemThe item to search for.

References LINKEDLIST::cmp_func, LINKEDLIST::head, and LINKEDLIST::tail.

◆ ListHead()

ListNode * ListHead ( LinkedList list)

Returns the head of the list.

Precondition: The list has been initialized.

Returns
The head of the list. NULL if list is empty.
Parameters
listMust be valid, non null, pointer to a linked list.

References LINKEDLIST::head, and LINKEDLIST::size.

◆ ListInit()

int ListInit ( LinkedList list,
cmp_routine  cmp_func,
free_function  free_func 
)

Initializes LinkedList. Must be called first and only once for List.

Returns
  • 0 on success.
  • EOUTOFMEM on failure.
Parameters
listMust be valid, non null, pointer to a linked list.
cmp_funcFunction used to compare items. (May be NULL).
free_funcFunction used to free items. (May be NULL).

References LINKEDLIST::cmp_func, LINKEDLIST::free_func, LINKEDLIST::freeNodeList, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.

◆ ListNext()

ListNode * ListNext ( LinkedList list,
ListNode node 
)

Returns the next item in the list.

Precondition: The list has been initialized.

Returns
The next item in the list. NULL if there are no more items in list.
Parameters
listMust be valid, non null, pointer to a linked list.
nodeNode from the list.

References LINKEDLIST::tail.

◆ ListPrev()

ListNode * ListPrev ( LinkedList list,
ListNode node 
)

Returns the previous item in the list.

Precondition: The list has been initialized.

Returns
The previous item in the list. NULL if there are no more items in list.
Parameters
listMust be valid, non null, pointer to a linked list.
nodeNode from the list.

References LINKEDLIST::head.

◆ ListSize()

long ListSize ( LinkedList list)

Returns the size of the list.

Precondition: The list has been initialized.

Returns
The number of items in the list.
Parameters
listMust be valid, non null, pointer to a linked list.

References LINKEDLIST::size.

◆ ListTail()

ListNode * ListTail ( LinkedList list)

Returns the tail of the list.

Precondition: The list has been initialized.

Returns
The tail of the list. NULL if list is empty.
Parameters
listMust be valid, non null, pointer to a linked list.

References LINKEDLIST::size, and LINKEDLIST::tail.