Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Examples

Linked list library
[Libraries]


Detailed Description

The linked list library provides a set of functions for manipulating linked lists.

A linked list is made up of elements where the first element must be a pointer. This pointer is used by the linked list library to form lists of the elements.

Lists are declared with the LIST() macro. The declaration specifies the name of the list that later is used with all list functions.

Lists can be manipulated by inserting or removing elements from either sides of the list (list_push(), list_add(), list_pop(), list_chop()). A specified element can also be removed from inside a list with list_remove(). The head and tail of a list can be extracted using list_head() and list_tail(), respecitively.


Files

file  list.h
 Linked list manipulation routines.
file  list.c
 Linked list library implementation.

Defines

#define LIST_CONCAT2(s1, s2)   s1##s2
#define LIST_CONCAT(s1, s2)   LIST_CONCAT2(s1, s2)
#define LIST(name)
 Declare a linked list.
#define NULL   0

Typedefs

typedef void ** list_t
 The linked list type.

Functions

void list_init (list_t list)
 Initialize a list.
void * list_head (list_t list)
 Get a pointer to the first element of a list.
void * list_tail (list_t list)
 Get the tail of a list.
void * list_pop (list_t list)
 Remove the first object on a list.
void list_push (list_t list, void *item)
 Add an item to the start of the list.
void * list_chop (list_t list)
 Remove the last object on the list.
void list_add (list_t list, void *item)
 Add an item at the end of a list.
void list_remove (list_t list, void *item)
 Remove a specific element from a list.
int list_length (list_t list)
 Get the length of a list.
void list_copy (list_t dest, list_t src)
 Duplicate a list.
void list_insert (list_t list, void *previtem, void *newitem)
 Insert an item after a specified item on the list.


Define Documentation

#define LIST name   ) 
 

Value:

static void *LIST_CONCAT(name,_list) = NULL; \
         static list_t name = (list_t)&LIST_CONCAT(name,_list)
Declare a linked list.

This macro declares a linked list with the specified type. The type must be a structure (struct) with its first element being a pointer. This pointer is used by the linked list library to form the linked lists.

Parameters:
name The name of the list.
Examples:
example-list.c.

Definition at line 85 of file list.h.


Function Documentation

void list_add list_t  list,
void *  item
 

Add an item at the end of a list.

This function adds an item to the end of the list.

Parameters:
list The list.
item A pointer to the item to be added.
See also:
list_push()
Examples:
example-list.c.

Definition at line 143 of file list.c.

References list_tail(), and NULL.

Referenced by mmem_alloc().

void * list_chop list_t  list  ) 
 

Remove the last object on the list.

This function removes the last object on the list and returns it.

Parameters:
list The list
Returns:
The removed object

Definition at line 180 of file list.c.

References NULL.

void list_copy list_t  dest,
list_t  src
 

Duplicate a list.

This function duplicates a list by copying the list reference, but not the elements.

Note:
This function does not copy the elements of the list, but merely duplicates the pointer to the first element of the list.
Parameters:
dest The destination list.
src The source list.

Definition at line 101 of file list.c.

void * list_head list_t  list  ) 
 

Get a pointer to the first element of a list.

This function returns a pointer to the first element of the list. The element will not be removed from the list.

Parameters:
list The list.
Returns:
A pointer to the first element on the list.
See also:
list_tail()
Examples:
example-list.c.

Definition at line 83 of file list.c.

void list_init list_t  list  ) 
 

Initialize a list.

This function initalizes a list. The list will be empty after this function has been called.

Parameters:
list The list to be initialized.
Examples:
example-list.c.

Definition at line 66 of file list.c.

References NULL.

Referenced by mmem_init().

void list_insert list_t  list,
void *  previtem,
void *  newitem
 

Insert an item after a specified item on the list.

Parameters:
list The list
previtem The item after which the new item should be inserted
newitem The new item that is to be inserted
Author:
Adam Dunkels
This function inserts an item right after a specified item on the list. This function is useful when using the list module to ordered lists.

If previtem is NULL, the new item is placed at the start of the list.

Definition at line 295 of file list.c.

References list_push(), and NULL.

int list_length list_t  list  ) 
 

Get the length of a list.

This function counts the number of elements on a specified list.

Parameters:
list The list.
Returns:
The length of the list.

Definition at line 267 of file list.c.

References NULL.

void * list_pop list_t  list  ) 
 

Remove the first object on a list.

This function removes the first object on the list and returns a pointer to the list.

Parameters:
list The list.
Returns:
The new head of the list.

Definition at line 212 of file list.c.

References NULL.

void list_remove list_t  list,
void *  item
 

Remove a specific element from a list.

This function removes a specified element from the list.

Parameters:
list The list.
item The item that is to be removed from the list.

Definition at line 232 of file list.c.

References NULL.

Referenced by mmem_free().

void * list_tail list_t  list  ) 
 

Get the tail of a list.

This function returns a pointer to the elements following the first element of a list. No elements are removed by this function.

Parameters:
list The list
Returns:
A pointer to the element after the first element on the list.
See also:
list_head()

Definition at line 118 of file list.c.

References NULL.

Referenced by list_add().


Generated on Thu Jun 22 17:45:43 2006 for Contiki 2.x by  doxygen 1.4.4