diff -r 545010bc5e71 -r 22eca559aded src/ucx/list.c --- a/src/ucx/list.c Sun Nov 20 12:43:44 2022 +0100 +++ b/src/ucx/list.c Sat Nov 26 17:07:08 2022 +0100 @@ -51,3 +51,32 @@ list->cl->destructor(list); cxFree(list->allocator, list); } + +int cxListCompare( + CxList const *list, + CxList const *other +) { + if (list->cl->compare == other->cl->compare) { + // same compare function, lists are compatible + return list->cl->compare(list, other); + } else { + // different compare functions, use iterator + if (list->size == other->size) { + CxIterator left = cxListBegin(list); + CxIterator right = cxListBegin(other); + for (size_t i = 0; i < list->size; i++) { + void *leftValue = cxIteratorCurrent(left); + void *rightValue = cxIteratorCurrent(right); + int d = list->cmpfunc(leftValue, rightValue); + if (d != 0) { + return d; + } + cxIteratorNext(left); + cxIteratorNext(right); + } + return 0; + } else { + return list->size < other->size ? -1 : 1; + } + } +}