17 array=malloc(
sizeof(
SArray));
22 array->
array=calloc(size,
sizeof(
void*));
53 array->
array[index]=elem;
56 else if(array->
array[index])
58 if(replace) array->
array[index]=elem;
64 array->
array[index]=elem;
79 else if(!array->
array[index])
86 if(elem) *elem=array->
array[index];
87 array->
array[index]=NULL;
103 else if(!array->
array[index])
108 else *elem=array->
array[index];
121 newarray=realloc(array->
array,size*
sizeof(
void*));
122 if(!newarray) result=1;
125 for(i=array->
capacity;i<size;i++) newarray[i]=NULL;
126 array->
array=newarray;
152 if(!array->
size) result=1;
159 fun(array->
array[i]);
174 for(ctrl=0,i=0,j=0;i<array->
capacity&&j<array->
size&&!ctrl;i++)
void arrayDelete(Array array)
Deletes an array.
Array newArray(int size)
Creates an empty array, with the specified initial capacity.
Iterator arrayIterator(Array array)
Creates an iterator from an array.
Implementation of a dynamic array.
void ** array
Array of pointers to this array's elements.
int arrayAt(Array array, int index, void **elem)
Provides the element at the specified position of an array.
void itDelete(Iterator it)
Deletes an iterator.
int arrayRemove(Array array, int index, void **elem)
Removes the element at the specified position of an array.
int itAdd(Iterator it, void *val)
Adds an element to an iterator.
int arrayMap(Array array, void(*fun)(void *))
Applies a function to the elements of an array.
int size
Number of element of this array.
int capacity
Current capacity of this array.
int arrayCapacity(Array array)
Return the capacity of an array.
int arraySize(Array array)
Returns the size of an array.
int arrayResize(Array array, int size)
Increases the capacity of an array.
int arrayInsert(Array array, int index, void *elem, int replace)
Inserts an new element at the specified position of an array.
Iterator newIt(int size)
Creates an iterator.