add cxListReverse()

Tue, 28 Dec 2021 17:41:51 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Dec 2021 17:41:51 +0100
changeset 490
e66551b47466
parent 489
af6be1e123aa
child 491
6d538177f746

add cxListReverse()

src/cx/list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/cx/list.h	Tue Dec 28 17:38:02 2021 +0100
     1.2 +++ b/src/cx/list.h	Tue Dec 28 17:41:51 2021 +0100
     1.3 @@ -114,6 +114,11 @@
     1.4              cx_list_s const *list,
     1.5              cx_list_s const *other
     1.6      );
     1.7 +
     1.8 +    /**
     1.9 +     * Member function for reversing the order of the items.
    1.10 +     */
    1.11 +    void (*reverse)(cx_list_s *list);
    1.12  } cx_list_class;
    1.13  
    1.14  /**
    1.15 @@ -249,6 +254,15 @@
    1.16  }
    1.17  
    1.18  /**
    1.19 + * Reverses the order of the items.
    1.20 + *
    1.21 + * @param list the list
    1.22 + */
    1.23 +static inline void cxListReverse(CxList list) {
    1.24 +    list->cl->reverse(list);
    1.25 +}
    1.26 +
    1.27 +/**
    1.28   * Compares a list to another list of the same type.
    1.29   *
    1.30   * First, the list sizes are compared. If they match, the lists are compared element-wise.
     2.1 --- a/src/linked_list.c	Tue Dec 28 17:38:02 2021 +0100
     2.2 +++ b/src/linked_list.c	Tue Dec 28 17:41:51 2021 +0100
     2.3 @@ -613,6 +613,11 @@
     2.4                          true, list->cmpfunc);
     2.5  }
     2.6  
     2.7 +static void cx_ll_reverse(cx_list_s *list) {
     2.8 +    cx_linked_list *ll = (cx_linked_list *) list;
     2.9 +    cx_linked_list_reverse((void **) &ll->begin, (void **) ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT);
    2.10 +}
    2.11 +
    2.12  static int cx_ll_compare(
    2.13          cx_list_s const *list,
    2.14          cx_list_s const *other
    2.15 @@ -642,7 +647,8 @@
    2.16          cx_ll_at,
    2.17          cx_ll_find,
    2.18          cx_ll_sort,
    2.19 -        cx_ll_compare
    2.20 +        cx_ll_compare,
    2.21 +        cx_ll_reverse
    2.22  };
    2.23  
    2.24  static cx_list_class cx_pointer_linked_list_class = {
    2.25 @@ -652,7 +658,8 @@
    2.26          cx_pll_at,
    2.27          cx_pll_find,
    2.28          cx_pll_sort,
    2.29 -        cx_pll_compare
    2.30 +        cx_pll_compare,
    2.31 +        cx_ll_reverse
    2.32  };
    2.33  
    2.34  CxList cxLinkedListCreate(

mercurial