Implementation of a dynamic array.
More...
Go to the source code of this file.
|
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.
- Author
- Rui Carlos Gonçalves
- Version
- 3.0
- Date
- 10/2011
Definition in file array.c.
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
.
- Attention
- This function puts at
elem
a pointer to the element at the specified position. Changes to this element will affect the element in the array.
- Parameters
-
array | the array |
index | the index of the element to be provided |
elem | pointer where the element at the specified position will be put |
- Returns
- 0 if there was an element at the specified position
1 otherwise
Definition at line 95 of file array.c.
int arrayCapacity |
( |
Array |
array | ) |
|
Return the capacity of an array.
- Parameters
-
- Returns
- the capacity of the array
Definition at line 142 of file array.c.
void arrayDelete |
( |
Array |
array | ) |
|
Deletes an array.
- Attention
- This function only frees the memory used by the array. It does not free the memory used by elements the array contains.
- Parameters
-
array | the array to be deleted |
Definition at line 35 of file array.c.
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
).
- Attention
- If the new element is
NULL
, it will not be inserted, and the size of the array will not change.
- Parameters
-
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 |
- Returns
- 0 if the new element was inserted
1 if the position was already filled
2 if the position was not valid
3 if it was not possible increase the array size
Definition at line 43 of file array.c.
Creates an iterator from an array.
- See Also
- Iterator
- Parameters
-
- Returns
NULL
if an error occurred
the iterator otherwise
Definition at line 169 of file array.c.
int arrayMap |
( |
Array |
array, |
|
|
void(*)(void *) |
fun |
|
) |
| |
Applies a function to the elements of an array.
The function to be applied must be of type void fun(void*)
.
- Parameters
-
array | the array |
fun | the function to be applied |
- Returns
- 0 if the array was not empty
1 otherwise
Definition at line 149 of file array.c.
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
.
- Attention
- This function does not free the memory used by the removed element.
- Parameters
-
array | the array |
index | the index of the element to be removed |
elem | pointer where the removed element should be put (or NULL ) |
- Returns
- 0 if an element was removed from the specified position
1 otherwise
Definition at line 71 of file array.c.
int arrayResize |
( |
Array |
array, |
|
|
int |
size |
|
) |
| |
Increases the capacity of an array.
The new capacity must be greater than the current one.
- Parameters
-
array | the array |
size | the new capacity |
- Returns
- 0 if the capacity of the array was increased
1 if it was not possible change the array capacity
2 if the new capacity was less than the current one
Definition at line 114 of file array.c.
int arraySize |
( |
Array |
array | ) |
|
Returns the size of an array.
- Parameters
-
- Returns
- the size of the array
Definition at line 135 of file array.c.
Array newArray |
( |
int |
size | ) |
|
Creates an empty array, with the specified initial capacity.
The initial capacity must be a positive number.
- Parameters
-
size | the initial capacity of the array |
- Returns
NULL
if an error occurred
the new array otherwise
Definition at line 12 of file array.c.