61 #define AMXC_ARRAY_AUTO_GROW_ITEMS 3
62 #define AMXC_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
73 for(
size_t index = start_pos; index <
array->items; index++) {
81 const size_t start_pos,
85 for(
unsigned int index = start_pos; index < start_pos + items; index++) {
87 if(
it->data != NULL) {
102 if(
array->buffer != NULL) {
108 array->buffer = buffer;
109 array->items = items;
117 const size_t start) {
118 size_t index = start;
119 while(index > 0 &&
array->buffer[index].data == NULL) {
127 const size_t start) {
128 size_t index = start;
129 while(index < array->items &&
array->buffer[index].data == NULL) {
133 return (index ==
array->items) ? 0 : index;
146 cmp(&
array->buffer[i], &
array->buffer[lo]) <= 0 &&
151 cmp(&
array->buffer[j], &
array->buffer[lo]) > 0 &&
164 if(cmp(&
array->buffer[lo], &
array->buffer[lo + 1]) > 0) {
168 if(high - (j + 1) > 1) {
171 if(cmp(&
array->buffer[high - 1], &
array->buffer[high]) > 0) {
188 (*array)->items = items;
189 (*array)->first_used = 0;
190 (*array)->last_used = 0;
200 if((*array)->buffer == NULL) {
223 free((*array)->buffer);
237 array->buffer = NULL;
238 array->first_used = 0;
239 array->last_used = 0;
252 array->items = items;
271 array->buffer = NULL;
273 array->first_used = 0;
274 array->last_used = 0;
282 size_t old_items = 0;
290 old_items =
array->items;
305 if(items ==
array->items) {
316 array->first_used = 0;
338 if(items ==
array->items) {
340 array->last_used = 0;
341 array->first_used = 0;
347 dst = &
array->buffer[items];
350 memmove(dst, src, len);
376 if(items ==
array->items) {
379 array->last_used = 0;
380 array->first_used = 0;
384 src = &
array->buffer[items];
388 memmove(dst, src, len);
403 if(
array->last_used != 0) {
407 if((
array->buffer != NULL) && (
array->buffer[0].data != NULL)) {
419 for(
size_t index = 0; index <
array->items; index++) {
420 if(
array->buffer[index].data != NULL) {
436 index =
array->last_used + 1;
439 if(index >=
array->items) {
457 (
array->buffer == NULL));
465 index =
array->first_used - 1;
475 const unsigned int index,
482 array->last_used = index;
483 array->first_used = index;
485 array->last_used = (
array->last_used < index) ? index :
array->last_used;
486 array->first_used = (
array->first_used > index) ? index :
array->first_used;
490 void* tmp =
it->data;
492 if((tmp != NULL) && (index ==
array->last_used)) {
495 if((tmp != NULL) && (index ==
array->first_used)) {
505 const unsigned int index) {
534 while(index < array->items &&
array->buffer[index].data != NULL) {
538 if(index < array->items) {
563 index =
array->items;
564 while(index > 0 &&
array->buffer[index - 1].data != NULL) {
569 it = &
array->buffer[index - 1];
602 if(
array->last_used == 0) {
606 i =
array->last_used;
609 if(
array->buffer[i].data == NULL) {
static size_t amxc_array_calculate_first_used(amxc_array_t *array, const size_t start)
static void amxc_array_initialize_items(amxc_array_t *array, const size_t start_pos)
static void amxc_array_clean_items(amxc_array_t *array, const size_t start_pos, const size_t items, amxc_array_it_delete_t func)
static size_t amxc_array_calculate_last_used(amxc_array_t *array, const size_t start)
#define AMXC_ARRAY_AUTO_GROW_ITEMS
static int amxc_array_sort_internal(amxc_array_t *const array, amxc_array_it_cmp_t cmp, int32_t lo, int32_t high)
static int amxc_array_realloc(amxc_array_t *array, const size_t items)
Ambiorix array API header file.
#define when_failed(x, l)
int(* amxc_array_it_cmp_t)(amxc_array_it_t *it1, amxc_array_it_t *it2)
Type definition of an array iterator compare callback function.
unsigned int amxc_array_it_index(const amxc_array_it_t *const it)
Gets the index of the iterator in the array.
int amxc_array_it_swap(amxc_array_it_t *const it1, amxc_array_it_t *const it2)
Swaps the content of the two array iterators.
amxc_array_it_t * amxc_array_get_last(const amxc_array_t *const array)
Gets the item iterator of the last used item in the array.
int amxc_array_shift_right(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shift all items to the right in the array.
amxc_array_it_t * amxc_array_set_data_at(amxc_array_t *const array, const unsigned int index, void *data)
Sets data at the given index.
void * amxc_array_take_first_data(amxc_array_t *const array)
Takes the data pointer from the first used item in the array.
size_t amxc_array_size(const amxc_array_t *const array)
Calculates the number of used items in the array.
amxc_array_it_t * amxc_array_get_last_free(const amxc_array_t *const array)
Gets the last free position in the array.
int amxc_array_shift_left(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shift all items to the left in the array.
void * amxc_array_take_last_data(amxc_array_t *const array)
Takes the data pointer from the last used item in the array.
int amxc_array_init(amxc_array_t *const array, const size_t items)
Initializes an array.
amxc_array_it_t * amxc_array_get_at(const amxc_array_t *const array, const unsigned int index)
Gets the item iterator for the given index.
int amxc_array_shrink(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shrinks the array.
amxc_array_it_t * amxc_array_get_first(const amxc_array_t *const array)
Gets the item iterator of the first used item in the array.
amxc_array_it_t * amxc_array_prepend_data(amxc_array_t *const array, void *data)
Adds an item before the first used item in the array.
bool amxc_array_is_empty(const amxc_array_t *const array)
Checks that the array is empty.
int8_t amxc_array_new(amxc_array_t **array, const size_t items)
Allocates an array.
void amxc_array_clean(amxc_array_t *const array, amxc_array_it_delete_t func)
Removes all items from the array.
amxc_array_it_t * amxc_array_get_first_free(const amxc_array_t *const array)
Gets the first free position in the array.
void(* amxc_array_it_delete_t)(amxc_array_it_t *it)
Definition of the array item delete callback function.
amxc_array_it_t * amxc_array_append_data(amxc_array_t *const array, void *data)
Adds an item after the last used item in the array.
int amxc_array_sort(amxc_array_t *const array, amxc_array_it_cmp_t cmp)
Sorts the content of the array.
int amxc_array_grow(amxc_array_t *const array, const size_t items)
Expands the array.
void amxc_array_delete(amxc_array_t **array, amxc_array_it_delete_t func)
Frees the previously allocated array.
The array iterator structure.
static unsigned int array[2006]
static amxc_htable_it_t it[2000]