src/cx/list.h

changeset 488
9138acaa494b
parent 484
9e6900b1cf9d
child 489
af6be1e123aa
     1.1 --- a/src/cx/list.h	Tue Dec 28 14:25:05 2021 +0100
     1.2 +++ b/src/cx/list.h	Tue Dec 28 17:24:18 2021 +0100
     1.3 @@ -81,12 +81,23 @@
     1.4      /**
     1.5       * Member function for finding an element.
     1.6       */
     1.7 -    size_t (*find)(cx_list_s *list, void *elem);
     1.8 +    size_t (*find)(
     1.9 +            cx_list_s *list,
    1.10 +            void *elem
    1.11 +    );
    1.12  
    1.13      /**
    1.14       * Member function for sorting the list in place.
    1.15       */
    1.16      void (*sort)(cx_list_s *list);
    1.17 +
    1.18 +    /**
    1.19 +     * Member function for comparing this list to another list of the same type.
    1.20 +     */
    1.21 +    int (*compare)(
    1.22 +            cx_list_s *list,
    1.23 +            cx_list_s *other
    1.24 +    );
    1.25  } cx_list_class;
    1.26  
    1.27  /**
    1.28 @@ -205,6 +216,22 @@
    1.29      list->cl->sort(list);
    1.30  }
    1.31  
    1.32 +/**
    1.33 + * Compares a list to another list of the same type.
    1.34 + *
    1.35 + * First, the list sizes are compared. If they match, the lists are compared element-wise.
    1.36 + *
    1.37 + * @param list the list
    1.38 + * @param other the list to compare to
    1.39 + * @return zero, if both lists are equal element wise, negative if the first list is smaller, zero if the first list is larger
    1.40 + */
    1.41 +static inline int cxListCompare(
    1.42 +        CxList list,
    1.43 +        CxList other
    1.44 +) {
    1.45 +    return list->cl->compare(list, other);
    1.46 +}
    1.47 +
    1.48  #ifdef __cplusplus
    1.49  } /* extern "C" */
    1.50  #endif

mercurial