Main Page | Modules | Data Structures | File List | Globals | Related Pages

lists.h File Reference


Detailed Description

Generic list functions.

Void lists store untyped objects (void pointers) and Int and Float lists are special cased to work with appropriately typed data. The interfaces for the three are the same except all functions for VoidLists are prefaced with 'VL', IntList with 'IL', and FloatList with 'FL'. Important The documentation says 'VAL' instead of just 'VL' as a prefix to all functions, macros do the expansion to the array version of lists by default so these are the same in practice.

And since these list data structures are basically arrays that are dynamically sized, inserting or removing elements is O(N) but accessing elements is O(1).

This module also has linked lists which are used very very rarely in VFML. You can access them by adding an additional L to the name, for example VLNew() -> VLLNew()


Examples

To iterate over the values in a VoidList:

VoidListPtr list = (some existing list); 
void *e;
int i;

for(i = 0 ; i < VLLength(list) ; i++) {
   e = VLIndex(list, i);
}

The same thing with a FloatList:

FloatListPtr list = (some existing list); 
float f;
int i;

for(i = 0 ; i < FLLength(list) ; i++) {
   f = FLIndex(list, i);
}

Go to the source code of this file.

Defines

#define VALLength(list)   (((VoidAListPtr)(list))->size)
 Returns the number of elements in the list.

#define VALIndex(list, index)   ( (index < ((VoidAListPtr)list)->size) ? (((VoidAListPtr)list)->array[index]) : (0) )
 Returns the element at the index (zero based).


Functions

VoidAListPtr VALNew (void)
 Creates a new list of the specified type.

void VALAppend (VoidAListPtr list, void *element)
 Append the element to the end of the list.

void VALPush (VoidAListPtr list, void *element)
 Push element on the head of the list.

void VALSort (VoidAListPtr list, int(*cmp)(const void *, const void *))
 Uses quick sort to sort the list in place with the passed comparision function.

void * VALRemove (VoidAListPtr list, long index)
 Removes the item at the specified index and returns it.

void VALInsert (VoidAListPtr list, void *element, long index)
 Inserts the element at the specified index.

void VALSet (VoidAListPtr list, long index, void *newVal)
 Sets the value at the specified index.

void VALFree (VoidAListPtr list)
 Frees the memory associated with the list.


Define Documentation

#define VALIndex list,
index   )     ( (index < ((VoidAListPtr)list)->size) ? (((VoidAListPtr)list)->array[index]) : (0) )
 

Returns the element at the index (zero based).

Note that the indexing is 0 based (like a C array).

#define VALLength list   )     (((VoidAListPtr)(list))->size)
 

Returns the number of elements in the list.


Function Documentation

void VALAppend VoidAListPtr  list,
void *  element
 

Append the element to the end of the list.

void VALFree VoidAListPtr  list  ) 
 

Frees the memory associated with the list.

You are responsible for any memory used by the elements of the list.

void VALInsert VoidAListPtr  list,
void *  element,
long  index
 

Inserts the element at the specified index.

The element that used to have that index will have an index one higher (that is, it shifts later elements over). Note that the indexing is 0 based (like a C array).

VoidAListPtr VALNew void   ) 
 

Creates a new list of the specified type.

void VALPush VoidAListPtr  list,
void *  element
 

Push element on the head of the list.

void* VALRemove VoidAListPtr  list,
long  index
 

Removes the item at the specified index and returns it.

Shifts later elements over. Note that the indexing is 0 based (like a C array).

void VALSet VoidAListPtr  list,
long  index,
void *  newVal
 

Sets the value at the specified index.

The previous value at the index is overwritten. Note that the indexing is 0 based (like a C array).

void VALSort VoidAListPtr  list,
int(*  cmp)(const void *, const void *)
 

Uses quick sort to sort the list in place with the passed comparision function.

Note this is not implemented for FloatLists.


Generated for VFML by doxygen hosted by SourceForge.net Logo