--- a/ucx/compare.c Thu Nov 28 17:53:13 2024 +0100 +++ b/ucx/compare.c Mon Jan 06 21:18:36 2025 +0100 @@ -30,9 +30,21 @@ #include <math.h> -int cx_cmp_int(void const *i1, void const *i2) { +int cx_vcmp_int(int a, int b) { + if (a == b) { + return 0; + } else { + return a < b ? -1 : 1; + } +} + +int cx_cmp_int(const void *i1, const void *i2) { int a = *((const int *) i1); int b = *((const int *) i2); + return cx_vcmp_int(a, b); +} + +int cx_vcmp_longint(long int a, long int b) { if (a == b) { return 0; } else { @@ -40,9 +52,13 @@ } } -int cx_cmp_longint(void const *i1, void const *i2) { +int cx_cmp_longint(const void *i1, const void *i2) { long int a = *((const long int *) i1); long int b = *((const long int *) i2); + return cx_vcmp_longint(a, b); +} + +int cx_vcmp_longlong(long long a, long long b) { if (a == b) { return 0; } else { @@ -50,9 +66,13 @@ } } -int cx_cmp_longlong(void const *i1, void const *i2) { +int cx_cmp_longlong(const void *i1, const void *i2) { long long a = *((const long long *) i1); long long b = *((const long long *) i2); + return cx_vcmp_longlong(a, b); +} + +int cx_vcmp_int16(int16_t a, int16_t b) { if (a == b) { return 0; } else { @@ -60,9 +80,13 @@ } } -int cx_cmp_int16(void const *i1, void const *i2) { +int cx_cmp_int16(const void *i1, const void *i2) { int16_t a = *((const int16_t *) i1); int16_t b = *((const int16_t *) i2); + return cx_vcmp_int16(a, b); +} + +int cx_vcmp_int32(int32_t a, int32_t b) { if (a == b) { return 0; } else { @@ -70,9 +94,13 @@ } } -int cx_cmp_int32(void const *i1, void const *i2) { +int cx_cmp_int32(const void *i1, const void *i2) { int32_t a = *((const int32_t *) i1); int32_t b = *((const int32_t *) i2); + return cx_vcmp_int32(a, b); +} + +int cx_vcmp_int64(int64_t a, int64_t b) { if (a == b) { return 0; } else { @@ -80,9 +108,13 @@ } } -int cx_cmp_int64(void const *i1, void const *i2) { +int cx_cmp_int64(const void *i1, const void *i2) { int64_t a = *((const int64_t *) i1); int64_t b = *((const int64_t *) i2); + return cx_vcmp_int64(a, b); +} + +int cx_vcmp_uint(unsigned int a, unsigned int b) { if (a == b) { return 0; } else { @@ -90,9 +122,13 @@ } } -int cx_cmp_uint(void const *i1, void const *i2) { +int cx_cmp_uint(const void *i1, const void *i2) { unsigned int a = *((const unsigned int *) i1); unsigned int b = *((const unsigned int *) i2); + return cx_vcmp_uint(a, b); +} + +int cx_vcmp_ulongint(unsigned long int a, unsigned long int b) { if (a == b) { return 0; } else { @@ -100,9 +136,13 @@ } } -int cx_cmp_ulongint(void const *i1, void const *i2) { +int cx_cmp_ulongint(const void *i1, const void *i2) { unsigned long int a = *((const unsigned long int *) i1); unsigned long int b = *((const unsigned long int *) i2); + return cx_vcmp_ulongint(a, b); +} + +int cx_vcmp_ulonglong(unsigned long long a, unsigned long long b) { if (a == b) { return 0; } else { @@ -110,9 +150,13 @@ } } -int cx_cmp_ulonglong(void const *i1, void const *i2) { +int cx_cmp_ulonglong(const void *i1, const void *i2) { unsigned long long a = *((const unsigned long long *) i1); unsigned long long b = *((const unsigned long long *) i2); + return cx_vcmp_ulonglong(a, b); +} + +int cx_vcmp_uint16(uint16_t a, uint16_t b) { if (a == b) { return 0; } else { @@ -120,9 +164,13 @@ } } -int cx_cmp_uint16(void const *i1, void const *i2) { +int cx_cmp_uint16(const void *i1, const void *i2) { uint16_t a = *((const uint16_t *) i1); uint16_t b = *((const uint16_t *) i2); + return cx_vcmp_uint16(a, b); +} + +int cx_vcmp_uint32(uint32_t a, uint32_t b) { if (a == b) { return 0; } else { @@ -130,9 +178,13 @@ } } -int cx_cmp_uint32(void const *i1, void const *i2) { +int cx_cmp_uint32(const void *i1, const void *i2) { uint32_t a = *((const uint32_t *) i1); uint32_t b = *((const uint32_t *) i2); + return cx_vcmp_uint32(a, b); +} + +int cx_vcmp_uint64(uint64_t a, uint64_t b) { if (a == b) { return 0; } else { @@ -140,19 +192,13 @@ } } -int cx_cmp_uint64(void const *i1, void const *i2) { +int cx_cmp_uint64(const void *i1, const void *i2) { uint64_t a = *((const uint64_t *) i1); uint64_t b = *((const uint64_t *) i2); - if (a == b) { - return 0; - } else { - return a < b ? -1 : 1; - } + return cx_vcmp_uint64(a, b); } -int cx_cmp_float(void const *f1, void const *f2) { - float a = *((const float *) f1); - float b = *((const float *) f2); +int cx_vcmp_float(float a, float b) { if (fabsf(a - b) < 1e-6f) { return 0; } else { @@ -160,12 +206,13 @@ } } -int cx_cmp_double( - void const *d1, - void const *d2 -) { - double a = *((const double *) d1); - double b = *((const double *) d2); +int cx_cmp_float(const void *f1, const void *f2) { + float a = *((const float *) f1); + float b = *((const float *) f2); + return cx_vcmp_float(a, b); +} + +int cx_vcmp_double(double a, double b) { if (fabs(a - b) < 1e-14) { return 0; } else { @@ -173,12 +220,33 @@ } } +int cx_cmp_double( + const void *d1, + const void *d2 +) { + double a = *((const double *) d1); + double b = *((const double *) d2); + return cx_vcmp_double(a, b); +} + +int cx_vcmp_intptr(intptr_t p1, intptr_t p2) { + if (p1 == p2) { + return 0; + } else { + return p1 < p2 ? -1 : 1; + } +} + int cx_cmp_intptr( - void const *ptr1, - void const *ptr2 + const void *ptr1, + const void *ptr2 ) { intptr_t p1 = *(const intptr_t *) ptr1; intptr_t p2 = *(const intptr_t *) ptr2; + return cx_vcmp_intptr(p1, p2); +} + +int cx_vcmp_uintptr(uintptr_t p1, uintptr_t p2) { if (p1 == p2) { return 0; } else { @@ -187,21 +255,17 @@ } int cx_cmp_uintptr( - void const *ptr1, - void const *ptr2 + const void *ptr1, + const void *ptr2 ) { uintptr_t p1 = *(const uintptr_t *) ptr1; uintptr_t p2 = *(const uintptr_t *) ptr2; - if (p1 == p2) { - return 0; - } else { - return p1 < p2 ? -1 : 1; - } + return cx_vcmp_uintptr(p1, p2); } int cx_cmp_ptr( - void const *ptr1, - void const *ptr2 + const void *ptr1, + const void *ptr2 ) { uintptr_t p1 = (uintptr_t) ptr1; uintptr_t p2 = (uintptr_t) ptr2;