LibRCG
3.1.1
|
Implementation of a dynamic array. More...
Go to the source code of this file.
Data Structures | |
struct | SArray |
Array structure. More... | |
Typedefs | |
typedef SArray * | Array |
Array definition. More... | |
Functions | |
Array | newArray (int size) |
Creates an empty array, with the specified initial capacity. More... | |
void | arrayDelete (Array array) |
Deletes an array. More... | |
int | arrayInsert (Array array, int index, void *elem, int replace) |
Inserts an new element at the specified position of an array. More... | |
int | arrayRemove (Array array, int index, void **elem) |
Removes the element at the specified position of an array. More... | |
int | arrayAt (Array array, int index, void **elem) |
Provides the element at the specified position of an array. More... | |
int | arrayResize (Array array, int size) |
Increases the capacity of an array. More... | |
int | arraySize (Array array) |
Returns the size of an array. More... | |
int | arrayCapacity (Array array) |
Return the capacity of an array. More... | |
int | arrayMap (Array array, void(*fun)(void *)) |
Applies a function to the elements of an array. More... | |
Iterator | arrayIterator (Array array) |
Creates an iterator from an array. More... | |
Implementation of a dynamic array.
Provides functions to create and manipulate a dynamic array with a desired length.
The array can resize itself whenever needed, while preserving the previous values.
Definition in file array.h.
int arrayAt | ( | Array | array, |
int | index, | ||
void ** | elem | ||
) |
Provides the element at the specified position of an array.
If there is no element at the specified position, it will be put the value NULL
at elem
.
elem
a pointer to the element at the specified position. Changes to this element will affect the element in the array.array | the array |
index | the index of the element to be provided |
elem | pointer where the element at the specified position will be put |
int arrayCapacity | ( | Array | array | ) |
void arrayDelete | ( | Array | array | ) |
int arrayInsert | ( | Array | array, |
int | index, | ||
void * | elem, | ||
int | replace | ||
) |
Inserts an new element at the specified position of an array.
The position, specified by argument index
, must be a non negative integer. If necessary, the capacity of the array will be increased to index+1
.
If the position is already filled, the replace
argument specifies whether the new element should be added (it will be added only if replace!=0
).
NULL
, it will not be inserted, and the size of the array will not change.array | the array |
index | the index at which the new element is to be inserted |
elem | the element to be inserted |
replace | specify whether old value will be replaced |
int arrayMap | ( | Array | array, |
void(*)(void *) | fun | ||
) |
int arrayRemove | ( | Array | array, |
int | index, | ||
void ** | elem | ||
) |
Removes the element at the specified position of an array.
Provides the value of the removed element if the value of elem
is not NULL
.
array | the array |
index | the index of the element to be removed |
elem | pointer where the removed element should be put (or NULL ) |
int arrayResize | ( | Array | array, |
int | size | ||
) |
Increases the capacity of an array.
The new capacity must be greater than the current one.
array | the array |
size | the new capacity |
int arraySize | ( | Array | array | ) |
LibRCG © 2004-2015 Rui Carlos Gonçalves