diff -r d4385f35f8b0 -r ef7cab6eb131 docs/Writerside/topics/compare.h.md --- a/docs/Writerside/topics/compare.h.md Tue Dec 16 21:33:58 2025 +0100 +++ b/docs/Writerside/topics/compare.h.md Wed Dec 17 19:05:50 2025 +0100 @@ -2,9 +2,10 @@ The `compare.h` header file contains a collection of compare functions for various primitive types. -They come in two flavors: +They come in three flavors: - prefixed with `cx_vcmp` they are taking the values directly as arguments - prefixed with `cx_cmp` the signature is designed to be compatible with the `cx_compare_func` function pointer type. +- prefixed with `cx_ccmp` the signature is designed to be compatible with the `cx_compare_func2` function pointer type. ## Examples @@ -13,10 +14,10 @@ ```C CxList *list = cxArrayListCreate( cxDefaultAllocator, // use the default allocator - cx_cmp_int32, // the compare function for the elements sizeof(int32_t), // the size of one element 256 // reseve space for 256 elements ); +cxSetCompareFunc(list, cx_cmp_int32); // the compare function for the elements ``` In the next example we simply want to compare two `double` values with rounding tolerance. @@ -29,6 +30,16 @@ } ``` +If you only have a `cx_compare_func` at hand but need to call a function that expects a `cx_compare_func2` and a `context`, +you can use `cx_ccmp_wrap` and the `cx_compare_func_wrapper` struct to wrap your function. + +```C +void some_fun(int x, int y, cx_compare_func2 f, void *context); + +cx_compare_func_wrapper wrapper = {my_cmp_fun}; +some_fun(x, y, cx_ccmp_wrap, &wrapper); +``` + ## List of Functions ```C @@ -73,6 +84,10 @@ int cx_cmp_uintptr(const void *a, const void *b); int cx_cmp_ulongint(const void *a, const void *b); int cx_cmp_ulonglong(const void *a, const void *b); + +// Three-arguments Flavour +int cx_ccmp_memcmp(const void *a, const void *b, void *size); +int cx_ccmp_wrap(const void *a, const void *b, void *cmp_fun_wrapper); ```