Next: , Up: Data structures   [Contents][Index]


5.2.3.1 Array

The array data structure is a simple array implementation. Each array has a size and capacity. The array indices range from zero to the array’s size minus one. You can put any kind of data into this array which fits into the size of a pointer. The array grows automatically if necessary.

Function: svz_array_t * svz_array_create (size_t capacity, svz_free_func_t destroy)

Create a new array with the initial capacity capacity and return a pointer to it. If capacity is zero it defaults to some value. If destroy is non-NULL, svz_array_destroy calls that function (typically used to free dynamically allocated memory). For example, if the array contains data allocated by svz_malloc, destroy should be specified as svz_free. If the array contains data which should not be released, destroy should be NULL.

Function: void svz_array_destroy (svz_array_t *array)

Completely destroy the array array. The array handle is invalid afterwards. The routine runs the destroy callback for each element of the array.

Function: void * svz_array_get (svz_array_t *array, size_t index)

Return the array element at the position index of the array array if the index is within the array range. Return NULL if not.

Function: void * svz_array_set (svz_array_t *array, size_t index, void *value)

Replace the array element at the position index of the array array with the value value and return the previous value at this index. Return NULL and do nothing if array is NULL or the index is out of the array range.

Function: void svz_array_add (svz_array_t *array, void *value)

Append the value value at the end of the array array. Do nothing if array is NULL.

Function: void * svz_array_del (svz_array_t *array, size_t index)

Remove the array element at the position index of the array array. Return its previous value or NULL if the index is out of the array’s range.

Function: size_t svz_array_size (svz_array_t *array)

Return the current size of array.

Macro: svz_array_foreach (array, value, i)

Expand into a for-statement header, for iterating over array. On each cycle, value is assigned to successive elements of array, and i the element’s position.


Next: Hashtable, Up: Data structures   [Contents][Index]