Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

list.h File Reference

Go to the source code of this file.

Data Structures

struct  List_
 This structure defines a linked list. More...

struct  ListElmt_
 This structure defines one element of the linked list. More...


Defines

#define list_size(liste)   ((liste)->taille)
 Return the number of elements in a linked list.

#define list_head(liste)   ((liste)->tete)
 Return a pointer to the first element of the linked list.

#define list_tail(liste)   ((liste)->queue)
 Return a pointer to the last element of the linked list.

#define list_is_head(liste, element)   ((element) == (liste)->tete ? 1 : 0)
 Test if a given element is the first element of a linked list.

#define list_is_tail(element)   ((element)->suivant == NULL ? 1 : 0)
 Test if a given element is the last element of a linked list.

#define list_data(element)   ((element)->donnee)
 Return a pointer to the data hold by an element.

#define list_next(element)   ((element)->suivant)
 Return a pointer to the next element in the linked list.


Typedefs

typedef ListElmt_ ListElmt
 This structure defines one element of the linked list.

typedef List_ List
 This structure defines a linked list.


Functions

void list_init (List *liste, void(*detruire)(void *donnee), int(*corresp)(const void *val1, const void *val2))
 Initialize the linked list. This function should be called first.

void list_destroy (List *liste)
 Destroy the linked list. This function free all allocated memory used by the list.

int list_ins_next (List *liste, ListElmt *element, const void *donnee)
 Insert a new element into the linked list.

int list_rem_next (List *liste, ListElmt *element, void **donnee)
 Remove an element from the linked list.

ListElmtlist_find (List *liste, ListElmt *from, void *data, ListElmt **prec)
 Search an element into the linked list.


Detailed Description

Header file for list.c

Definition in file list.h.


Define Documentation

#define list_data element       ((element)->donnee)
 

Return a pointer to the data hold by an element.

Parameters:
element Pointer to the linked list element.
Returns:
This macro returns a pointer to the data associted with element.
Examples:
test_list.c.

Definition at line 117 of file list.h.

Referenced by chtbl_find(), chtbl_lookup(), chtbl_next(), and list_find().

#define list_head liste       ((liste)->tete)
 

Return a pointer to the first element of the linked list.

Parameters:
liste Pointer to the list structure.
Examples:
test_list.c.

Definition at line 88 of file list.h.

Referenced by chtbl_find(), chtbl_lookup(), chtbl_next(), and list_find().

#define list_is_head liste,
element       ((element) == (liste)->tete ? 1 : 0)
 

Test if a given element is the first element of a linked list.

Parameters:
liste Pointer to the list structure.
element Pointer to the linked list element.
Returns:
This macro returns 1 if element point to the beginning of liste. Otherwise it returns 0.

Definition at line 102 of file list.h.

#define list_is_tail element       ((element)->suivant == NULL ? 1 : 0)
 

Test if a given element is the last element of a linked list.

Parameters:
liste Pointer to the list structure.
element Pointer to the linked list element.
Returns:
This macro returns 1 if element point to the end of liste. Otherwise it returns 0.

Definition at line 110 of file list.h.

#define list_next element       ((element)->suivant)
 

Return a pointer to the next element in the linked list.

Parameters:
element Pointer to the linked list element.
Returns:
This macro returns a pointer to the element next to element.
Examples:
test_list.c.

Definition at line 124 of file list.h.

Referenced by chtbl_find(), chtbl_lookup(), chtbl_next(), and list_find().

#define list_size liste       ((liste)->taille)
 

Return the number of elements in a linked list.

Parameters:
liste Pointer to the list structure.

Definition at line 82 of file list.h.

Referenced by list_destroy(), list_ins_next(), and list_rem_next().

#define list_tail liste       ((liste)->queue)
 

Return a pointer to the last element of the linked list.

Parameters:
liste Pointer to the list structure.
Examples:
test_list.c.

Definition at line 94 of file list.h.


Function Documentation

void list_destroy List   liste
 

Destroy the linked list. This function free all allocated memory used by the list.

Parameters:
liste Pointer to a linked list structure (that you need to destroy).

Definition at line 40 of file list.c.

References List_::detruire, list_rem_next(), and list_size.

Referenced by chtbl_destroy().

ListElmt* list_find List   liste,
ListElmt   from,
void *    data,
ListElmt **    prec
 

Search an element into the linked list.

Parameters:
liste Pointer to the linked list structure.
from Pointer to the linked list's element where the search begins. If 'point' in NULL, then the search begins at the beginning of the linked list.
data Pointer to a data a user defined structure that contains the data to search for.
prec Pointer to a pointer that will receive the address of the element before the found element.
Returns:
  • If the function finds an element that matches data, then it returns a pointer to this element. In this case, prec points to the previous element (unless the found element was the first element in the linked list ... in this the value of prec is NULL).
  • If there is no element that matches data, then the function returns NULL.

Definition at line 231 of file list.c.

References List_::corresp, list_data, list_head, and list_next.

Referenced by chtbl_remove().

void list_init List   liste,
void(*    detruire)(void *donnee),
int(*    corresp)(const void *val1, const void *val2)
 

Initialize the linked list. This function should be called first.

Parameters:
liste Pointer to a linked list structure (that will be initialized).
detruire Pointer to a function that will be called to free the memory used to store one link of the list. Please note that:
  • This function depends on the type of data stored into the linked list.
  • detruire could be a NULL pointer (if user's data are not dtnamically allocated).
corresp Pointer to a function that will be called to compare to elements. Please note that this function depends on the type of data stored into the linked list. The function must returns 1 if the elements' datas are identical; 0 otherwise.

Definition at line 21 of file list.c.

References List_::corresp, List_::detruire, List_::queue, List_::taille, and List_::tete.

Referenced by chtbl_init().

int list_ins_next List   liste,
ListElmt   element,
const void *    donnee
 

Insert a new element into the linked list.

Parameters:
liste Pointer to a linked list structure.
element Pointer to an (existing) element of the linked list. The new element will be inserted AFTER the element pointed by element.
donnee Pointer to the data to insert. Please note that the data is NOT copied into the linked list.
Returns:
Upon successful completion the function return the value 0. Otherwise the function returns -1.
Warning:
The inserted data is NOT copied into the linked list! Therefore you should not free it unless you know exactly what you are doing.

Definition at line 69 of file list.c.

References ListElmt_::donnee, list_size, List_::queue, ListElmt_::suivant, List_::taille, and List_::tete.

Referenced by chtbl_insert(), and stack_push().

int list_rem_next List   liste,
ListElmt   element,
void **    donnee
 

Remove an element from the linked list.

Parameters:
liste Pointer to a linked list structure.
element Pointer to an (existing) element of the linked list. The element to delete is the element AFTER the element pointed by element. If you want to remove the first element of the list, then you must specify NULL as second argument for the function list_rem_next().
donnee Pointer that vill point to the data stored by the removed element.
Returns:
Upon successful completion the function return the value 0. Otherwise the function returns -1.
Warning:
This function does NOT free the element's data (it only frees the element's structure). Therefore you should use donnee to free the element's data yourself.

Definition at line 145 of file list.c.

References ListElmt_::donnee, list_size, List_::queue, ListElmt_::suivant, List_::taille, and List_::tete.

Referenced by chtbl_remove(), list_destroy(), and stack_pop().


Generated on Thu Apr 3 16:23:46 2003 for Common_C_libraries by doxygen1.3-rc1