diff -r f549fd9fbd8f -r 54565fd74e74 src/array_list.c --- a/src/array_list.c Wed Sep 18 00:02:18 2024 +0200 +++ b/src/array_list.c Sat Sep 28 15:47:28 2024 +0200 @@ -55,7 +55,7 @@ size_t *size, size_t *capacity, size_t index, - void const *src, + const void *src, size_t elem_size, size_t elem_count, struct cx_array_reallocator_s *reallocator @@ -125,7 +125,7 @@ size_t *size, size_t *capacity, cx_compare_func cmp_func, - void const *sorted_data, + const void *sorted_data, size_t elem_size, size_t elem_count, struct cx_array_reallocator_s *reallocator @@ -166,7 +166,7 @@ // declare the source and destination indices/pointers size_t si = 0, di = 0; - char const *src = sorted_data; + const char *src = sorted_data; char *dest = *target; // find the first insertion point @@ -232,10 +232,10 @@ } size_t cx_array_binary_search_inf( - void const *arr, + const void *arr, size_t size, size_t elem_size, - void const *elem, + const void *elem, cx_compare_func cmp_func ) { // special case: empty array @@ -245,7 +245,7 @@ int result; // cast the array pointer to something we can use offsets with - char const *array = arr; + const char *array = arr; // check the first array element result = cmp_func(elem, array); @@ -269,7 +269,7 @@ while (left_index <= right_index) { pivot_index = left_index + (right_index - left_index) / 2; - char const *arr_elem = array + pivot_index * elem_size; + const char *arr_elem = array + pivot_index * elem_size; result = cmp_func(elem, arr_elem); if (result == 0) { // found it! @@ -347,7 +347,7 @@ struct cx_array_reallocator_s *alloc ) { // retrieve the pointer to the list allocator - CxAllocator const *al = alloc->ptr1; + const CxAllocator *al = alloc->ptr1; // use the list allocator to reallocate the memory return cxRealloc(al, array, capacity * elem_size); @@ -378,7 +378,7 @@ static size_t cx_arl_insert_array( struct cx_list_s *list, size_t index, - void const *array, + const void *array, size_t n ) { // out of bounds and special case check @@ -389,7 +389,7 @@ // do we need to move some elements? if (index < list->collection.size) { - char const *first_to_move = (char const *) arl->data; + const char *first_to_move = (const char *) arl->data; first_to_move += index * list->collection.elem_size; size_t elems_to_move = list->collection.size - index; size_t start_of_moved = index + n; @@ -433,7 +433,7 @@ static size_t cx_arl_insert_sorted( struct cx_list_s *list, - void const *sorted_data, + const void *sorted_data, size_t n ) { // get a correctly typed pointer to the list @@ -459,14 +459,14 @@ static int cx_arl_insert_element( struct cx_list_s *list, size_t index, - void const *element + const void *element ) { return 1 != cx_arl_insert_array(list, index, element, 1); } static int cx_arl_insert_iter( struct cx_iterator_s *iter, - void const *elem, + const void *elem, int prepend ) { struct cx_list_s *list = iter->src_handle.m; @@ -570,11 +570,11 @@ } static void *cx_arl_at( - struct cx_list_s const *list, + const struct cx_list_s *list, size_t index ) { if (index < list->collection.size) { - cx_array_list const *arl = (cx_array_list const *) list; + const cx_array_list *arl = (const cx_array_list *) list; char *space = arl->data; return space + index * list->collection.elem_size; } else { @@ -584,12 +584,12 @@ static ssize_t cx_arl_find_remove( struct cx_list_s *list, - void const *elem, + const void *elem, bool remove ) { assert(list->collection.cmpfunc != NULL); assert(list->collection.size < SIZE_MAX / 2); - char *cur = ((cx_array_list const *) list)->data; + char *cur = ((const cx_array_list *) list)->data; for (ssize_t i = 0; i < (ssize_t) list->collection.size; i++) { if (0 == list->collection.cmpfunc(elem, cur)) { @@ -619,13 +619,13 @@ } static int cx_arl_compare( - struct cx_list_s const *list, - struct cx_list_s const *other + const struct cx_list_s *list, + const struct cx_list_s *other ) { assert(list->collection.cmpfunc != NULL); if (list->collection.size == other->collection.size) { - char const *left = ((cx_array_list const *) list)->data; - char const *right = ((cx_array_list const *) other)->data; + const char *left = ((const cx_array_list *) list)->data; + const char *right = ((const cx_array_list *) other)->data; for (size_t i = 0; i < list->collection.size; i++) { int d = list->collection.cmpfunc(left, right); if (d != 0) { @@ -642,21 +642,21 @@ static void cx_arl_reverse(struct cx_list_s *list) { if (list->collection.size < 2) return; - void *data = ((cx_array_list const *) list)->data; + void *data = ((const cx_array_list *) list)->data; size_t half = list->collection.size / 2; for (size_t i = 0; i < half; i++) { cx_array_swap(data, list->collection.elem_size, i, list->collection.size - 1 - i); } } -static bool cx_arl_iter_valid(void const *it) { - struct cx_iterator_s const *iter = it; - struct cx_list_s const *list = iter->src_handle.c; +static bool cx_arl_iter_valid(const void *it) { + const struct cx_iterator_s *iter = it; + const struct cx_list_s *list = iter->src_handle.c; return iter->index < list->collection.size; } -static void *cx_arl_iter_current(void const *it) { - struct cx_iterator_s const *iter = it; +static void *cx_arl_iter_current(const void *it) { + const struct cx_iterator_s *iter = it; return iter->elem_handle; } @@ -669,13 +669,13 @@ iter->index++; iter->elem_handle = ((char *) iter->elem_handle) - + ((struct cx_list_s const *) iter->src_handle.c)->collection.elem_size; + + ((const struct cx_list_s *) iter->src_handle.c)->collection.elem_size; } } static void cx_arl_iter_prev(void *it) { struct cx_iterator_s *iter = it; - cx_array_list const* list = iter->src_handle.c; + const cx_array_list *list = iter->src_handle.c; if (iter->base.remove) { iter->base.remove = false; cx_arl_remove(iter->src_handle.m, iter->index); @@ -689,7 +689,7 @@ static struct cx_iterator_s cx_arl_iterator( - struct cx_list_s const *list, + const struct cx_list_s *list, size_t index, bool backwards ) { @@ -727,7 +727,7 @@ }; CxList *cxArrayListCreate( - CxAllocator const *allocator, + const CxAllocator *allocator, cx_compare_func comparator, size_t elem_size, size_t initial_capacity