Home | History | Annotate | Download | only in shared

Lines Matching refs:array

25 #include <shared/array.h>
27 /* basic pointer array growing in steps */
30 static int array_realloc(struct array *array, size_t new_total)
32 void *tmp = realloc(array->array, sizeof(void *) * new_total);
35 array->array = tmp;
36 array->total = new_total;
40 void array_init(struct array *array, size_t step)
43 array->array = NULL;
44 array->count = 0;
45 array->total = 0;
46 array->step = step;
49 int array_append(struct array *array, const void *element)
53 if (array->count + 1 >= array->total) {
54 int r = array_realloc(array, array->total + array->step);
58 idx = array->count;
59 array->array[idx] = (void *)element;
60 array->count++;
64 int array_append_unique(struct array *array, const void *element)
66 void **itr = array->array;
67 void **itr_end = itr + array->count;
71 return array_append(array, element);
74 void array_pop(struct array *array) {
75 array->count--;
76 if (array->count + array->step < array->total) {
77 int r = array_realloc(array, array->total - array->step);
83 void array_free_array(struct array *array) {
84 free(array->array);
85 array->count = 0;
86 array->total = 0;
90 void array_sort(struct array *array, int (*cmp)(const void *a, const void *b))
92 qsort(array->array, array->count, sizeof(void *), cmp);
95 int array_remove_at(struct array *array, unsigned int pos)
97 if (array->count <= pos)
100 array->count--;
101 if (pos < array->count)
102 memmove(array->array + pos, array->array + pos + 1,
103 sizeof(void *) * (array->count - pos));
105 if (array->count + array->step < array->total) {
106 int r = array_realloc(array, array->total - array->step);