31 if(!(
this = calloc(1,
sizeof(
struct array_list))))
return NULL;
35 if(!(this->
array = calloc(
sizeof(
void*), (
size_t) this->
size))) {
46 for(i = 0; i < this->
length; i++)
55 if(i >= this->
length)
return NULL;
56 return this->
array[i];
64 if(max < this->
size)
return 0;
65 new_size =
max(this->size << 1, max);
66 if(!(t = realloc(this->
array, new_size*
sizeof(
void*))))
return -1;
68 (void)memset(this->
array + this->size, 0, (new_size-this->size)*
sizeof(
void*));
69 this->size = new_size;
78 this->
array[idx] = data;
void( array_list_free_fn)(void *data)
static int array_list_expand_internal(struct array_list *this, int max)
struct array_list * array_list_new(array_list_free_fn *free_fn)
int array_list_put_idx(struct array_list *this, int idx, void *data)
int array_list_add(struct array_list *this, void *data)
array_list_free_fn * free_fn
void array_list_free(struct array_list *this)
void * array_list_get_idx(struct array_list *this, int i)
int array_list_length(struct array_list *this)
#define ARRAY_LIST_DEFAULT_SIZE