4
* This file, as the rest of the project is under MIT license.
5
* see http://opensource.org/licenses/MIT
11
* This file contains an imlpementation of a "dynamic" array, it is usefule when
12
* dealing with lare amounts of data that may change over time, or with an
13
* unknowned numebr of items.
15
* Note that accsess time is constant, but write time is not guarenteed to be.
17
* When the size of the array is equal to the number of elements in it, it will
18
* re-allocate the array with a larger size.
22
* The padding that is added when expanding the array.
24
#define ARRAY_PADDING 8
27
* Represents a for each function.
29
* @param self the dynamic array.
30
* @param data the data to be passed to the each iteration.
31
* @returns data to be put in a new DynamicArray, if used with
32
* dynamic_array_for_each_with_return.
34
typedef void * (* ForEachFunc)(DynamicArray * self, void * data);
37
* an opaque data structure that represents the dynamic array.
39
typedef struct _DynamicArray DynamicArray;
42
* Create a new dynamic array.
44
* @param len The length of the initial array.
45
* @param item_size The size of the items to be stored.
47
DymamicArray * dynamic_array_new (size_t len);
50
* Frees the dynamic array.
52
* after this is run the data will be lost.
54
void dynamic_array_free (DynamicArray * self);
58
* Get an item from the array.
60
void * dynamic_array_get (DynamicArray * self, int index);
63
* Get the length of the array.
65
size_t dymanic_array_len (DynamicArray * self);
69
* Add an item to the array.
71
void dynamic_array_add (DynamicArray * self, void * item);
74
* Dumps a copy of the. Must be cast.
76
* Is not freed when the dynamic array is freed.
80
void ** dynamic_array_dump_array (DynamicArray * self);
83
* Use a function on the array.
85
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
89
* same as dynamic_array_for_each (), with the difference that it returns a new
92
DynamicArray * dynamic_array_for_each_with_return (DynamicArray * self,