src/linked_list.c

changeset 486
d7ca126eab7f
parent 481
eef025d82a34
child 487
4bd19279778c
     1.1 --- a/src/linked_list.c	Mon Dec 27 17:16:32 2021 +0100
     1.2 +++ b/src/linked_list.c	Tue Dec 28 14:16:04 2021 +0100
     1.3 @@ -396,6 +396,28 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +int cx_linked_list_compare(
     1.8 +        void *begin_left,
     1.9 +        void *begin_right,
    1.10 +        ptrdiff_t loc_advance,
    1.11 +        ptrdiff_t loc_data,
    1.12 +        int follow_ptr,
    1.13 +        CxListComparator cmp_func
    1.14 +) {
    1.15 +    void *left = begin_left, *right = begin_right;
    1.16 +
    1.17 +    while (left != NULL && right != NULL) {
    1.18 +        int result = cmp_func(ll_data(left), ll_data(right));
    1.19 +        if (result != 0) return result;
    1.20 +        left = ll_advance(left);
    1.21 +        right = ll_advance(right);
    1.22 +    }
    1.23 +
    1.24 +    if (left != NULL) { return 1; }
    1.25 +    else if (right != NULL) { return -1; }
    1.26 +    else { return 0; }
    1.27 +}
    1.28 +
    1.29  void cx_linked_list_reverse(
    1.30          void **begin,
    1.31          void **end,

mercurial