diff -r 75ae1dccd101 -r 0458bff0b1cd src/cx/list.h --- a/src/cx/list.h Tue Oct 05 16:33:11 2021 +0200 +++ b/src/cx/list.h Wed Oct 06 14:10:19 2021 +0200 @@ -87,6 +87,11 @@ * Member function for retrieving the last element. */ void *(*last)(cx_list_s *list); + + /** + * Member function for sorting the list in place. + */ + void (*sort)(cx_list_s *list); } cx_list_class; /** @@ -136,7 +141,9 @@ * @param elem a pointer to the element to add * @return zero on success, non-zero on memory allocation failure */ -int cxListAdd(CxList list, void *elem); +static inline int cxListAdd(CxList list, void *elem) { + return list->cl->add(list, elem); +} /** * Inserts an item at the specified index. @@ -154,7 +161,9 @@ * @return zero on success, non-zero on memory allocation failure * or when the index is out of bounds */ -int cxListInsert(CxList list, size_t index, void *elem); +static inline int cxListInsert(CxList list, size_t index, void *elem) { + return list->cl->insert(list, index, elem); +} /** * Removes the element at the specified index. @@ -162,7 +171,9 @@ * @param index the index of the element * @return zero on success, non-zero if the index is out of bounds */ -int cxListRemove(CxList list, size_t index); +static inline int cxListRemove(CxList list, size_t index) { + return list->cl->remove(list, index); +} /** * Returns a pointer to the element at the specified index. @@ -171,7 +182,9 @@ * @param index the index of the element * @return a pointer to the element or \c NULL if the index is out of bounds */ -void *cxListAt(CxList list, size_t index); +static inline void *cxListAt(CxList list, size_t index) { + return list->cl->at(list, index); +} /** * Returns the index of the first element that equals \p elem. @@ -182,7 +195,9 @@ * @param elem the element to find * @return the index of the element or \c (size+1) if the element is not found */ -size_t cxListFind(CxList list, void *elem); +static inline size_t cxListFind(CxList list, void *elem) { + return list->cl->find(list, elem); +} /** * Returns a pointer to the last element of the list. @@ -194,7 +209,20 @@ * @param list the list * @return a pointer to the last element or \c NULL if the list is empty */ -void *cxListLast(CxList list); +static inline void *cxListLast(CxList list) { + return list->cl->last(list); +} + +/** + * Sorts the list in place. + * + * \remark The underlying sort algorithm is implementation defined. + * + * @param list the list + */ +static inline void cxListSort(CxList list) { + list->cl->sort(list); +} #ifdef __cplusplus } /* extern "C" */