# HG changeset patch # User Mike Becker # Date 1758988030 -7200 # Node ID 40c3b850f8595b25998df68520c2c9733d1042e6 # Parent c8af55ed4cae682ab9355e5271c5718d0c41d8fe add size_t compare functions diff -r c8af55ed4cae -r 40c3b850f859 docs/Writerside/topics/compare.h.md --- a/docs/Writerside/topics/compare.h.md Sat Sep 27 17:03:35 2025 +0200 +++ b/docs/Writerside/topics/compare.h.md Sat Sep 27 17:47:10 2025 +0200 @@ -48,6 +48,7 @@ cx_vcmp_uint16 cx_vcmp_uint32 cx_vcmp_uint64 +cx_vcmp_size cx_vcmp_uintptr cx_vcmp_ulongint cx_vcmp_ulonglong @@ -67,6 +68,7 @@ cx_cmp_uint16 cx_cmp_uint32 cx_cmp_uint64 +cx_cmp_size cx_cmp_uintptr cx_cmp_ulongint cx_cmp_ulonglong diff -r c8af55ed4cae -r 40c3b850f859 src/compare.c --- a/src/compare.c Sat Sep 27 17:03:35 2025 +0200 +++ b/src/compare.c Sat Sep 27 17:47:10 2025 +0200 @@ -198,6 +198,20 @@ return cx_vcmp_uint64(a, b); } +int cx_vcmp_size(size_t a, size_t b) { + if (a == b) { + return 0; + } else { + return a < b ? -1 : 1; + } +} + +int cx_cmp_size(const void *i1, const void *i2) { + size_t a = *((const size_t *) i1); + size_t b = *((const size_t *) i2); + return cx_vcmp_size(a, b); +} + int cx_vcmp_float(float a, float b) { if (fabsf(a - b) < 1e-6f) { return 0; diff -r c8af55ed4cae -r 40c3b850f859 src/cx/compare.h --- a/src/cx/compare.h Sat Sep 27 17:03:35 2025 +0200 +++ b/src/cx/compare.h Sat Sep 27 17:47:10 2025 +0200 @@ -423,6 +423,36 @@ int cx_vcmp_uint64(uint64_t i1, uint64_t i2); /** + * Compares two integers of type size_t. + * + * @note the parameters deliberately have type @c void* to be + * compatible with #cx_compare_func without the need of a cast. + * + * @param i1 pointer to size_t one + * @param i2 pointer to size_t two + * @retval -1 if the left argument is less than the right argument + * @retval 0 if both arguments are equal + * @retval 1 if the left argument is greater than the right argument + */ +cx_attr_nonnull +cx_attr_nodiscard +cx_attr_export +int cx_cmp_size(const void *i1, const void *i2); + +/** + * Compares two integers of type size_t. + * + * @param i1 size_t one + * @param i2 size_t two + * @retval -1 if the left argument is less than the right argument + * @retval 0 if both arguments are equal + * @retval 1 if the left argument is greater than the right argument + */ +cx_attr_nodiscard +cx_attr_export +int cx_vcmp_size(size_t i1, size_t i2); + +/** * Compares two real numbers of type float with precision 1e-6f. * * @note the parameters deliberately have type @c void* to be