--- a/ucx/cx/collection.h Tue Oct 14 21:02:26 2025 +0200 +++ b/ucx/cx/collection.h Sat Nov 08 23:06:11 2025 +0100 @@ -142,14 +142,24 @@ /** * Indicates whether the collection can guarantee that the stored elements are currently sorted. * - * This may return false even when the elements are sorted. - * It is totally up to the implementation of the collection whether it keeps track of the order of its elements. + * This may return @c false even when the elements are sorted. + * It is totally up to the implementation of the collection when to check if the elements are sorted. + * It is usually a good practice to establish this property as an invariant that does not need + * to be re-checked on certain operations. * * @param c a pointer to a struct that contains #CX_COLLECTION_BASE * @retval true if the elements are currently sorted wrt. the collection's compare function * @retval false if the order of elements is unknown */ -#define cxCollectionSorted(c) ((c)->collection.sorted) +#define cxCollectionSorted(c) ((c)->collection.sorted || (c)->collection.size == 0) + +/** + * Sets the compare function for a collection. + * + * @param c a pointer to a struct that contains #CX_COLLECTION_BASE + * @param func (@c cx_compare_func) the compare function that shall be used by @c c + */ +#define cxCollectionCompareFunc(c, func) (c)->collection.cmpfunc = (func) /** * Sets a simple destructor function for this collection.