core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

simple_list.h File Reference


Detailed Description

Simple macros for type-safe, intrusive lists.

Intended to work with a list sentinal which is created as an empty list. Insert & delete are O(1).

Author:
(C) 1997, Keith Whitwell


Data Structures

struct  simple_node

Defines

#define remove_from_list(elem)
 Remove an element from list.
#define insert_at_head(list, elem)
 Insert an element to the list head.
#define insert_at_tail(list, elem)
 Insert an element to the list tail.
#define move_to_head(list, elem)
 Move an element to the list head.
#define move_to_tail(list, elem)
 Move an element to the list tail.
#define make_empty_list(sentinal)
 Make a empty list empty.
#define first_elem(list)   ((list)->next)
 Get list first element.
#define last_elem(list)   ((list)->prev)
 Get list last element.
#define next_elem(elem)   ((elem)->next)
 Get next element.
#define prev_elem(elem)   ((elem)->prev)
 Get previous element.
#define at_end(list, elem)   ((elem) == (list))
 Test whether element is at end of the list.
#define is_empty_list(list)   ((list)->next == (list))
 Test if a list is empty.
#define foreach(ptr, list)   for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
 Walk through the elements of a list.
#define foreach_s(ptr, t, list)   for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)
 Walk through the elements of a list.


Define Documentation

#define at_end ( list,
elem   )     ((elem) == (list))

Test whether element is at end of the list.

Parameters:
list list.
elem element.
Returns:
non-zero if element is at end of list, or zero otherwise.

#define first_elem ( list   )     ((list)->next)

Get list first element.

Parameters:
list list.
Returns:
pointer to first element.

#define foreach ( ptr,
list   )     for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )

Walk through the elements of a list.

Parameters:
ptr pointer to the current element.
list list.
Note:
It should be followed by a { } block or a single statement, as in a for loop.

#define foreach_s ( ptr,
t,
list   )     for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)

Walk through the elements of a list.

Same as foreach but lets you unlink the current value during a list traversal. Useful for freeing a list, element by element.

Parameters:
ptr pointer to the current element.
t temporary pointer.
list list.
Note:
It should be followed by a { } block or a single statement, as in a for loop.

#define insert_at_head ( list,
elem   ) 

Value:

do {                                            \
   (elem)->prev = list;                         \
   (elem)->next = (list)->next;                 \
   (list)->next->prev = elem;                   \
   (list)->next = elem;                         \
} while(0)
Insert an element to the list head.

Parameters:
list list.
elem element to insert.

#define insert_at_tail ( list,
elem   ) 

Value:

do {                                            \
   (elem)->next = list;                         \
   (elem)->prev = (list)->prev;                 \
   (list)->prev->next = elem;                   \
   (list)->prev = elem;                         \
} while(0)
Insert an element to the list tail.

Parameters:
list list.
elem element to insert.

#define is_empty_list ( list   )     ((list)->next == (list))

Test if a list is empty.

Parameters:
list list.
Returns:
non-zero if list empty, or zero otherwise.

#define last_elem ( list   )     ((list)->prev)

Get list last element.

Parameters:
list list.
Returns:
pointer to last element.

#define make_empty_list ( sentinal   ) 

Value:

do {                                            \
   (sentinal)->next = sentinal;                 \
   (sentinal)->prev = sentinal;                 \
} while (0)
Make a empty list empty.

Parameters:
sentinal list (sentinal element).

#define move_to_head ( list,
elem   ) 

Value:

do {                                            \
   remove_from_list(elem);                      \
   insert_at_head(list, elem);                  \
} while (0)
Move an element to the list head.

Parameters:
list list.
elem element to move.

#define move_to_tail ( list,
elem   ) 

Value:

do {                                            \
   remove_from_list(elem);                      \
   insert_at_tail(list, elem);                  \
} while (0)
Move an element to the list tail.

Parameters:
list list.
elem element to move.

#define next_elem ( elem   )     ((elem)->next)

Get next element.

Parameters:
elem element.
Returns:
pointer to next element.

#define prev_elem ( elem   )     ((elem)->prev)

Get previous element.

Parameters:
elem element.
Returns:
pointer to previous element.

#define remove_from_list ( elem   ) 

Value:

do {                                            \
   (elem)->next->prev = (elem)->prev;           \
   (elem)->prev->next = (elem)->next;           \
} while (0)
Remove an element from list.

Parameters:
elem element to remove.


Generated on Sun Sep 27 06:47:46 2009 for Mesa Main by  doxygen 1.5.4