src/linked_list.c

changeset 487
4bd19279778c
parent 486
d7ca126eab7f
child 488
9138acaa494b
equal deleted inserted replaced
486:d7ca126eab7f 487:4bd19279778c
58 58
59 size_t cx_linked_list_find( 59 size_t cx_linked_list_find(
60 void *start, 60 void *start,
61 ptrdiff_t loc_advance, 61 ptrdiff_t loc_advance,
62 ptrdiff_t loc_data, 62 ptrdiff_t loc_data,
63 int follow_ptr, 63 bool follow_ptr,
64 CxListComparator cmp_func, 64 CxListComparator cmp_func,
65 void *elem 65 void *elem
66 ) { 66 ) {
67 assert(start != NULL); 67 assert(start != NULL);
68 assert(loc_advance >= 0); 68 assert(loc_advance >= 0);
282 282
283 static void *cx_linked_list_sort_merge( 283 static void *cx_linked_list_sort_merge(
284 ptrdiff_t loc_prev, 284 ptrdiff_t loc_prev,
285 ptrdiff_t loc_next, 285 ptrdiff_t loc_next,
286 ptrdiff_t loc_data, 286 ptrdiff_t loc_data,
287 int follow_ptr, 287 bool follow_ptr,
288 size_t length, 288 size_t length,
289 void *ls, 289 void *ls,
290 void *le, 290 void *le,
291 void *re, 291 void *re,
292 CxListComparator cmp_func 292 CxListComparator cmp_func
338 void **begin, 338 void **begin,
339 void **end, 339 void **end,
340 ptrdiff_t loc_prev, 340 ptrdiff_t loc_prev,
341 ptrdiff_t loc_next, 341 ptrdiff_t loc_next,
342 ptrdiff_t loc_data, 342 ptrdiff_t loc_data,
343 int follow_ptr, 343 bool follow_ptr,
344 CxListComparator cmp_func 344 CxListComparator cmp_func
345 ) { 345 ) {
346 assert(begin != NULL); 346 assert(begin != NULL);
347 assert(loc_next >= 0); 347 assert(loc_next >= 0);
348 assert(loc_data >= 0); 348 assert(loc_data >= 0);
399 int cx_linked_list_compare( 399 int cx_linked_list_compare(
400 void *begin_left, 400 void *begin_left,
401 void *begin_right, 401 void *begin_right,
402 ptrdiff_t loc_advance, 402 ptrdiff_t loc_advance,
403 ptrdiff_t loc_data, 403 ptrdiff_t loc_data,
404 int follow_ptr, 404 bool follow_ptr,
405 CxListComparator cmp_func 405 CxListComparator cmp_func
406 ) { 406 ) {
407 void *left = begin_left, *right = begin_right; 407 void *left = begin_left, *right = begin_right;
408 408
409 while (left != NULL && right != NULL) { 409 while (left != NULL && right != NULL) {
585 cx_list_s *list, 585 cx_list_s *list,
586 void *elem 586 void *elem
587 ) { 587 ) {
588 return cx_linked_list_find(((cx_linked_list *) list)->begin, 588 return cx_linked_list_find(((cx_linked_list *) list)->begin,
589 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 589 CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
590 0, list->cmpfunc, elem); 590 false, list->cmpfunc, elem);
591 } 591 }
592 592
593 static size_t cx_pll_find( 593 static size_t cx_pll_find(
594 cx_list_s *list, 594 cx_list_s *list,
595 void *elem 595 void *elem
596 ) { 596 ) {
597 return cx_linked_list_find(((cx_linked_list *) list)->begin, 597 return cx_linked_list_find(((cx_linked_list *) list)->begin,
598 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 598 CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
599 1, list->cmpfunc, elem); 599 true, list->cmpfunc, elem);
600 } 600 }
601 601
602 static void cx_ll_sort(cx_list_s *list) { 602 static void cx_ll_sort(cx_list_s *list) {
603 cx_linked_list *ll = (cx_linked_list *) list; 603 cx_linked_list *ll = (cx_linked_list *) list;
604 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 604 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
605 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 605 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
606 0, list->cmpfunc); 606 false, list->cmpfunc);
607 } 607 }
608 608
609 static void cx_pll_sort(cx_list_s *list) { 609 static void cx_pll_sort(cx_list_s *list) {
610 cx_linked_list *ll = (cx_linked_list *) list; 610 cx_linked_list *ll = (cx_linked_list *) list;
611 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 611 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
612 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 612 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
613 1, list->cmpfunc); 613 true, list->cmpfunc);
614 } 614 }
615 615
616 static cx_list_class cx_linked_list_class = { 616 static cx_list_class cx_linked_list_class = {
617 cx_ll_add, 617 cx_ll_add,
618 cx_ll_insert, 618 cx_ll_insert,

mercurial