Lines Matching refs:arr

28   struct array_list *arr;  in array_list_new()  local
30 arr = (struct array_list*)calloc(1, sizeof(struct array_list)); in array_list_new()
31 if(!arr) return NULL; in array_list_new()
32 arr->size = ARRAY_LIST_DEFAULT_SIZE; in array_list_new()
33 arr->length = 0; in array_list_new()
34 arr->free_fn = free_fn; in array_list_new()
35 if(!(arr->array = (void**)calloc(sizeof(void*), arr->size))) { in array_list_new()
36 free(arr); in array_list_new()
39 return arr; in array_list_new()
43 array_list_free(struct array_list *arr) in array_list_free() argument
46 for(i = 0; i < arr->length; i++) in array_list_free()
47 if(arr->array[i]) arr->free_fn(arr->array[i]); in array_list_free()
48 free(arr->array); in array_list_free()
49 free(arr); in array_list_free()
53 array_list_get_idx(struct array_list *arr, int i) in array_list_get_idx() argument
55 if(i >= arr->length) return NULL; in array_list_get_idx()
56 return arr->array[i]; in array_list_get_idx()
59 static int array_list_expand_internal(struct array_list *arr, int max) in array_list_expand_internal() argument
64 if(max < arr->size) return 0; in array_list_expand_internal()
65 new_size = arr->size << 1; in array_list_expand_internal()
68 if(!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1; in array_list_expand_internal()
69 arr->array = (void**)t; in array_list_expand_internal()
70 (void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*)); in array_list_expand_internal()
71 arr->size = new_size; in array_list_expand_internal()
76 array_list_put_idx(struct array_list *arr, int idx, void *data) in array_list_put_idx() argument
78 if(array_list_expand_internal(arr, idx+1)) return -1; in array_list_put_idx()
79 if(arr->array[idx]) arr->free_fn(arr->array[idx]); in array_list_put_idx()
80 arr->array[idx] = data; in array_list_put_idx()
81 if(arr->length <= idx) arr->length = idx + 1; in array_list_put_idx()
86 array_list_add(struct array_list *arr, void *data) in array_list_add() argument
88 return array_list_put_idx(arr, arr->length, data); in array_list_add()
92 array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *)) in array_list_sort() argument
94 qsort(arr->array, arr->length, sizeof(arr->array[0]), in array_list_sort()
99 array_list_length(struct array_list *arr) in array_list_length() argument
101 return arr->length; in array_list_length()