src/cx/list.h

changeset 647
2e6e9d9f2159
parent 641
d402fead3386
child 655
7340c4255f1f
     1.1 --- a/src/cx/list.h	Wed Feb 08 18:56:58 2023 +0100
     1.2 +++ b/src/cx/list.h	Wed Feb 08 20:26:09 2023 +0100
     1.3 @@ -164,6 +164,15 @@
     1.4      );
     1.5  
     1.6      /**
     1.7 +     * Member function for swapping two elements.
     1.8 +     */
     1.9 +    int (*swap)(
    1.10 +            struct cx_list_s *list,
    1.11 +            size_t i,
    1.12 +            size_t j
    1.13 +    );
    1.14 +
    1.15 +    /**
    1.16       * Member function for element lookup.
    1.17       */
    1.18      void *(*at)(
    1.19 @@ -401,6 +410,26 @@
    1.20  }
    1.21  
    1.22  /**
    1.23 + * Swaps two items in the list.
    1.24 + *
    1.25 + * Implementations should only allocate temporary memory for the swap, if
    1.26 + * it is necessary.
    1.27 + *
    1.28 + * @param list the list
    1.29 + * @param i the index of the first element
    1.30 + * @param j the index of the second element
    1.31 + * @return zero on success, non-zero if one of the indices is out of bounds
    1.32 + */
    1.33 +__attribute__((__nonnull__))
    1.34 +static inline int cxListSwap(
    1.35 +        CxList *list,
    1.36 +        size_t i,
    1.37 +        size_t j
    1.38 +) {
    1.39 +    return list->cl->swap(list, i, j);
    1.40 +}
    1.41 +
    1.42 +/**
    1.43   * Returns a pointer to the element at the specified index.
    1.44   *
    1.45   * @param list the list

mercurial