Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

slist.h File Reference

Implementation of a single linked list. More...

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  _slist
 The actual list. More...

struct  _slist_e
 Implementation of an element in the linked list. More...

struct  slist_iter
 List iterator. More...


Typedefs

typedef _slist_e slist_e
 Implementation of an element in the linked list.

typedef _slist slist
 The actual list.


Functions

void slist_init (slist *s)
 Initialise a list.

void slist_delete (slist *s)
 Free all memory used by the list s.

void slist_delete_special (slist *s, void(*func)(void *))
 Free all memory used by the list in a custom way.

void slist_delete_list_only (slist *s)
 Free all memory used by the elements in list s.

void * slist_first (const slist *s)
 Return the first data element from s.

void * slist_last (const slist *s)
 Return the last data element from the list.

void * slist_at_iter (slist_iter iter)
 Retrieve the data element at the iterator from the list.

void slist_prepend (slist *s, void *data)
 Insert a new data element at the start of the list.

void slist_append (slist *s, void *data)
 Insert a new data element at the end of the list.

void slist_insert (slist *s, slist_iter *iter, void *data)
 Insert a new data element right before the iterator.

void * slist_remove_first (slist *s)
 Remove the first data element from the list.

void * slist_remove_last (slist *s)
 Remove the last data element from the list.

void * slist_remove_at_iter (slist *s, slist_iter iter)
 Remove the data element at the iterator.

slist_iter slist_begin_iter (const slist *s)
 Create an iterator that points at the first data element of the list.

slist_iter slist_end_iter (const slist *s)
 Create an iterator that points right behind the last element of the list.

void * slist_iter_and_next (slist_iter *iter)
 Retrieve the data element at the iterator's position, and move to the next element in the list.

void slist_for_each (const slist *s, void(*func)(void *data, void *userdata), void *userdata)
 Call func() for every element in the list.

void slist_for_each_range (slist_iter start, slist_iter end, void(*func)(void *data, void *userdata), void *userdata)
 Call func() for every element between the iterators start and end, including start and excluding end.

int slist_iter_eq (slist_iter a, slist_iter b)
 Test two iterators for equality.

int slist_iter_at_end (slist_iter iter)
 Test if an iterator is at the end of a list.

slist_iter slist_find (const slist *s, const void *data)
 Search for a data item in the list.

slist_iter slist_find_if (const slist *s, const void *compare, int(*func)(const void *data, const void *compare))
 Search for a data item in the list with a user-defined function for comparing two elements.

unsigned int slist_length (const slist *s)
 Determine the length of the list.


Detailed Description

Implementation of a single linked list.

This list only takes data elements of type void*. You will have to cast the elements back to the right type after retrieving them. It is allowed to insert NULL elements.

Definition in file slist.h.


Function Documentation

void slist_append slist   s,
void *    data
 

Insert a new data element at the end of the list.

Parameters:
s  List to add the element data to.
data  Pointer to the data element to be added.

Definition at line 122 of file slist.c.

void* slist_at_iter slist_iter    iter
 

Retrieve the data element at the iterator from the list.

Parameters:
iter  Iterator to dereference.
Returns:
Pointer to the data element at the iterator's position in the list, or NULL if the iterator is not valid.

Definition at line 103 of file slist.c.

slist_iter slist_begin_iter const slist   s
 

Create an iterator that points at the first data element of the list.

Parameters:
s  The list to create the iterator for.
Returns:
An iterator that points to the first data element of the list, or which is invalid if s is an empty list.

Definition at line 249 of file slist.c.

void slist_delete slist   s
 

Free all memory used by the list s.

Calls free() for every slist_elem struct in the list, and for every data element.

Parameters:
s  List to be deleted.

Definition at line 71 of file slist.c.

void slist_delete_list_only slist   s
 

Free all memory used by the elements in list s.

Calls free() for every slist_elem struct in s, leaving the data elements alone.

Parameters:
s  List to be deleted.

Definition at line 79 of file slist.c.

void slist_delete_special slist   s,
void(*    func)(void *)
 

Free all memory used by the list in a custom way.

Calls free() for every slist_elem struct in s, and the user-defined func() for every data element.

Parameters:
s  List to be deleted.
func  Function that will clean up the data element.

Definition at line 55 of file slist.c.

slist_iter slist_end_iter const slist   s
 

Create an iterator that points right behind the last element of the list.

(It does not point at an actual data element.)

Parameters:
s  The list to create the iterator for.
Returns:
An iterator that points right after the last element in list s.

Definition at line 262 of file slist.c.

slist_iter slist_find const slist   s,
const void *    data
 

Search for a data item in the list.

If the item could not be found, and end of list iterator is returned. Use slist_iter_at_end or slist_iter_eq to test for this condition.

Parameters:
s  The list to be searched.
data  The element to look for.

Definition at line 323 of file slist.c.

slist_iter slist_find_if const slist   s,
const void *    compare,
int(*    func)(const void *data, const void *compare)
 

Search for a data item in the list with a user-defined function for comparing two elements.

If the item could not be found, and end of list iterator is returned. Use slist_iter_at_end or slist_iter_eq to test for this condition.

Parameters:
s  The list to be searched.
compare  The element to look for.
func  A function that compares two elements, and returns a non-zero value if they are equal.

Definition at line 335 of file slist.c.

void* slist_first const slist   s
 

Return the first data element from s.

Parameters:
s  List to fetch the first data element from.
Returns:
Pointer to the first data element of s, or NULL if s is empty.

Definition at line 87 of file slist.c.

void slist_for_each const slist   s,
void(*    func)(void *data, void *userdata),
void *    userdata
 

Call func() for every element in the list.

The variable userdata can be used to pass extra information to the function func.

Parameters:
s  The list to take all elements from.
func  The function that will be called.
userdata  The second argument to func.

Definition at line 292 of file slist.c.

void slist_for_each_range slist_iter    start,
slist_iter    end,
void(*    func)(void *data, void *userdata),
void *    userdata
 

Call func() for every element between the iterators start and end, including start and excluding end.

The variable userdata can be used to pass extra information to the function func.

Parameters:
start  Points to the begin of the range.
end  Points right after the end of the range.
func  The function that will be called.
userdata  The second argument to func.

Definition at line 304 of file slist.c.

void slist_init slist   s
 

Initialise a list.

The elements of the slist struct s are set to NULL.

Parameters:
s  List to initialise.

Definition at line 46 of file slist.c.

void slist_insert slist   s,
slist_iter   iter,
void *    data
 

Insert a new data element right before the iterator.

Parameters:
s  List to add the element data to.
iter  Insertion position.
data  Pointer to the data element to be added.

Definition at line 140 of file slist.c.

void* slist_iter_and_next slist_iter   iter
 

Retrieve the data element at the iterator's position, and move to the next element in the list.

If the iterator was not valid, NULL is returned and /a iter remains unchanged.

Parameters:
iter  The iterator to dereference and move to the next element.
Returns:
Pointer to the data element at the iterator's position, or NULL if iter is not valid.

Definition at line 275 of file slist.c.

int slist_iter_at_end slist_iter    iter
 

Test if an iterator is at the end of a list.

Parameters:
iter  Iterator to be tested.

Definition at line 358 of file slist.c.

int slist_iter_eq slist_iter    a,
slist_iter    b
 

Test two iterators for equality.

Parameters:
a  First iterator to be tested.
b  Second iterator to be tested.

Definition at line 351 of file slist.c.

void* slist_last const slist   s
 

Return the last data element from the list.

Parameters:
s  List to fetch the first data element from.
Returns:
Pointer to the last data element of s, or NULL if s is empty.

Definition at line 95 of file slist.c.

unsigned int slist_length const slist   s
 

Determine the length of the list.

Parameters:
s  The length of this list will be calculated.
Returns:
Length of the list.

Definition at line 365 of file slist.c.

void slist_prepend slist   s,
void *    data
 

Insert a new data element at the start of the list.

Parameters:
s  List to add the element data to.
data  Pointer to the data element to be added.

Definition at line 110 of file slist.c.

void* slist_remove_at_iter slist   s,
slist_iter    iter
 

Remove the data element at the iterator.

The iterator is no longer valid after this call.

Parameters:
s  List to remove the element from.
iter  Iterator to use for removal.
Returns:
Pointer to the removed data element.

Definition at line 222 of file slist.c.

void* slist_remove_first slist   s
 

Remove the first data element from the list.

Parameters:
s  List to remove the element from.
Returns:
Pointer to the removed data element.

Definition at line 168 of file slist.c.

void* slist_remove_last slist   s
 

Remove the last data element from the list.

Parameters:
s  List to remove the element from.
Returns:
Pointer to the removed data element.

Definition at line 190 of file slist.c.


Generated on Sun Feb 16 23:39:59 2003 for FreeLCD by doxygen1.2.18