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

array.h File Reference

Dynamic Arrays for arbitrary data. More...

Go to the source code of this file.

Defines

Typedefs

Functions


Detailed Description

Dynamic Arrays for arbitrary data.


Define Documentation

#define array_at array,
index   )     ((array)->elements[index])
 

Extracts an element at a specified position.

This is a macro alternative to array_get. It is faster, but does not check boundaries.


Typedef Documentation

typedef void(* DestructorFnc)(void *element)
 

Destructor function.

Parameters:
element element to be destroyed.
A destructor function frees the elements data and the element itself. It is used in array functions which remove elements.

typedef int(* EqualsFnc)(void *element, void *user_data)
 

Equivalence comparator.

Parameters:
element Element to be compared.
used_data Data used for comparison.
An EqualsFnc returns 1 if a given element is "equal" to the user data, or 0 it it is not. This type of function can be used to compare certain attributes of a given element with supplied data.

See also:
array_find_equals()


Function Documentation

int array_append Array array,
void *  newElement
 

Appends an element to an array.

If necessary, the array will be increased automatically.

void array_clear Array array,
DestructorFnc  destructor
 

Removes all elements.

Parameters:
array An array
destructor A function which frees each element and its contents. The destructor is responsible for de-allocating the element and all its contents. If the destructor is NULL, the element data will not be freed.

Array* array_create  ) 
 

Creates a new array.

Creates a new array with a buffer for 32 elements.

Array* array_create_sized int  bufferSize  ) 
 

Creates a new array.

Parameters:
bufferSize Maximal number of contained elements. Creates a new array with a pre-set buffer size. Prevents re-allocating memory space if the array size is known in advance.

void array_destroy Array array,
DestructorFnc  destructor
 

Removes the array and all elements.

Parameters:
array An array
destructor A function which frees each element and its contents. The destructor is responsible for de-allocating the element and all its contents. If the destructor is NULL, the element data will not be freed.

void* array_find_equals Array array,
EqualsFnc  equals,
void *  user_data
 

Finds an array element.

Parameters:
array An array.
equals Comparator function. Compares each element to user_data. Must return 0 on failure and 1 on success.
user_data Data to be compared.
Finds the first element for which equals(element, user_data) != 0.

Returns:
Pointer to an element on success, NULL on failure.
See also:
EqualsFnc

int array_find_index Array array,
void *  element
 

Finds the index of a specified element.

Parameters:
array An array.
element An element to find.
Returns:
Index on success, else -1.

void* array_get Array array,
int  index
 

Returns an element at a specified index.

Parameters:
array An array.
index An index

int array_increase Array array,
int  new_places
 

Increases the array's available memory size.

This function is mainly for internal use. It is called implicitly bu array_add().

Parameters:
array An array.
new_places Number of new places to add.

int array_insert_before Array array,
int  index,
void *  newElement
 

Inserts an element before the specified index.

Parameters:
array An array.
index The index.
newElement Element to be inserted.
Returns:
true (1) if the element was inserted, false (0) else.

void array_remove Array array,
int  index,
DestructorFnc  destructor
 

Removes an element from an array.

Parameters:
array An array.
index Index of the element.
destructor Destructor function which has to be called to erase the element.

void array_remove_element Array array,
void *  element,
DestructorFnc  destructor
 

Removes an element from an array.

Parameters:
array An array.
element An element.
destructor Destructor function which has to be called to erase the element.


Generated on Fri Jan 20 10:12:18 2006 by  doxygen 1.4.2