src/array_list.c

changeset 660
4738a9065907
parent 655
7340c4255f1f
child 662
d0d95740071b
equal deleted inserted replaced
659:4a06fd63909a 660:4738a9065907
110 void *arr, 110 void *arr,
111 size_t elem_size, 111 size_t elem_size,
112 size_t idx1, 112 size_t idx1,
113 size_t idx2 113 size_t idx2
114 ) { 114 ) {
115 assert(arr != NULL);
116
115 // short circuit 117 // short circuit
116 if (idx1 == idx2) return; 118 if (idx1 == idx2) return;
117 119
118 char sbo_mem[CX_ARRAY_SWAP_SBO_SIZE]; 120 char sbo_mem[CX_ARRAY_SWAP_SBO_SIZE];
119 void *tmp; 121 void *tmp;
317 319
318 static size_t cx_arl_find( 320 static size_t cx_arl_find(
319 struct cx_list_s const *list, 321 struct cx_list_s const *list,
320 void const *elem 322 void const *elem
321 ) { 323 ) {
324 assert(list->cmpfunc != NULL);
322 char *cur = ((cx_array_list const *) list)->data; 325 char *cur = ((cx_array_list const *) list)->data;
323 326
324 for (size_t i = 0; i < list->size; i++) { 327 for (size_t i = 0; i < list->size; i++) {
325 if (0 == list->cmpfunc(elem, cur)) { 328 if (0 == list->cmpfunc(elem, cur)) {
326 return i; 329 return i;
330 333
331 return list->size; 334 return list->size;
332 } 335 }
333 336
334 static void cx_arl_sort(struct cx_list_s *list) { 337 static void cx_arl_sort(struct cx_list_s *list) {
338 assert(list->cmpfunc != NULL);
335 qsort(((cx_array_list *) list)->data, 339 qsort(((cx_array_list *) list)->data,
336 list->size, 340 list->size,
337 list->itemsize, 341 list->itemsize,
338 list->cmpfunc 342 list->cmpfunc
339 ); 343 );
341 345
342 static int cx_arl_compare( 346 static int cx_arl_compare(
343 struct cx_list_s const *list, 347 struct cx_list_s const *list,
344 struct cx_list_s const *other 348 struct cx_list_s const *other
345 ) { 349 ) {
350 assert(list->cmpfunc != NULL);
346 if (list->size == other->size) { 351 if (list->size == other->size) {
347 char const *left = ((cx_array_list const *) list)->data; 352 char const *left = ((cx_array_list const *) list)->data;
348 char const *right = ((cx_array_list const *) other)->data; 353 char const *right = ((cx_array_list const *) other)->data;
349 for (size_t i = 0; i < list->size; i++) { 354 for (size_t i = 0; i < list->size; i++) {
350 int d = list->cmpfunc(left, right); 355 int d = list->cmpfunc(left, right);

mercurial