Thu, 18 Dec 2025 17:50:15 +0100
update ucx
| 174 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | /** | |
| 440 | 29 | * @file compare.h |
| 30 | * @brief A collection of simple compare functions. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 174 | 34 | */ |
| 35 | ||
| 36 | #ifndef UCX_COMPARE_H | |
| 37 | #define UCX_COMPARE_H | |
| 38 | ||
| 39 | #include "common.h" | |
| 40 | ||
| 41 | #ifdef __cplusplus | |
| 42 | extern "C" { | |
| 43 | #endif | |
| 44 | ||
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
45 | /** |
| 440 | 46 | * A comparator function comparing two arbitrary values. |
| 47 | * | |
| 48 | * All functions from compare.h with the cx_cmp prefix are | |
| 49 | * compatible with this signature and can be used as | |
| 845 | 50 | * compare function for collections or other implementations |
| 440 | 51 | * that need to be type-agnostic. |
| 52 | * | |
| 53 | * For simple comparisons the cx_vcmp family of functions | |
| 54 | * can be used, but they are NOT compatible with this function | |
| 55 | * pointer. | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
56 | */ |
| 870 | 57 | typedef int (*cx_compare_func)(const void *left, const void *right); |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
58 | |
| 174 | 59 | /** |
| 1016 | 60 | * A comparator function comparing two arbitrary values. |
| 61 | * | |
| 62 | * Functions with this signature allow specifying a pointer to custom data. | |
| 63 | */ | |
| 64 | typedef int (*cx_compare_func2)(const void *left, const void *right, void *data); | |
| 65 | ||
| 66 | /** | |
| 174 | 67 | * Compares two integers of type int. |
| 68 | * | |
| 440 | 69 | * @note the parameters deliberately have type @c void* to be |
| 70 | * compatible with #cx_compare_func without the need of a cast. | |
| 71 | * | |
| 174 | 72 | * @param i1 pointer to integer one |
| 73 | * @param i2 pointer to integer two | |
| 440 | 74 | * @retval -1 if the left argument is less than the right argument |
| 75 | * @retval 0 if both arguments are equal | |
| 76 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 77 | */ |
| 870 | 78 | cx_attr_nonnull cx_attr_nodiscard |
| 79 | CX_EXPORT int cx_cmp_int(const void *i1, const void *i2); | |
| 174 | 80 | |
| 81 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
82 | * Compares two integers of type int. |
| 440 | 83 | * |
| 84 | * @param i1 integer one | |
| 85 | * @param i2 integer two | |
| 86 | * @retval -1 if the left argument is less than the right argument | |
| 87 | * @retval 0 if both arguments are equal | |
| 88 | * @retval 1 if the left argument is greater than the right argument | |
| 89 | */ | |
| 90 | cx_attr_nodiscard | |
| 870 | 91 | CX_EXPORT int cx_vcmp_int(int i1, int i2); |
| 440 | 92 | |
| 93 | /** | |
| 174 | 94 | * Compares two integers of type long int. |
| 95 | * | |
| 440 | 96 | * @note the parameters deliberately have type @c void* to be |
| 97 | * compatible with #cx_compare_func without the need of a cast. | |
| 98 | * | |
| 174 | 99 | * @param i1 pointer to long integer one |
| 100 | * @param i2 pointer to long integer two | |
| 440 | 101 | * @retval -1 if the left argument is less than the right argument |
| 102 | * @retval 0 if both arguments are equal | |
| 103 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 104 | */ |
| 870 | 105 | cx_attr_nonnull cx_attr_nodiscard |
| 106 | CX_EXPORT int cx_cmp_longint(const void *i1, const void *i2); | |
| 174 | 107 | |
| 108 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
109 | * Compares two integers of type long int. |
| 440 | 110 | * |
| 111 | * @param i1 long integer one | |
| 112 | * @param i2 long integer two | |
| 113 | * @retval -1 if the left argument is less than the right argument | |
| 114 | * @retval 0 if both arguments are equal | |
| 115 | * @retval 1 if the left argument is greater than the right argument | |
| 116 | */ | |
| 117 | cx_attr_nodiscard | |
| 870 | 118 | CX_EXPORT int cx_vcmp_longint(long int i1, long int i2); |
| 440 | 119 | |
| 120 | /** | |
| 174 | 121 | * Compares two integers of type long long. |
| 122 | * | |
| 440 | 123 | * @note the parameters deliberately have type @c void* to be |
| 124 | * compatible with #cx_compare_func without the need of a cast. | |
| 125 | * | |
| 174 | 126 | * @param i1 pointer to long long one |
| 127 | * @param i2 pointer to long long two | |
| 440 | 128 | * @retval -1 if the left argument is less than the right argument |
| 129 | * @retval 0 if both arguments are equal | |
| 130 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 131 | */ |
| 870 | 132 | cx_attr_nonnull cx_attr_nodiscard |
| 133 | CX_EXPORT int cx_cmp_longlong(const void *i1, const void *i2); | |
| 174 | 134 | |
| 135 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
136 | * Compares two integers of type long long. |
| 440 | 137 | * |
| 138 | * @param i1 long long int one | |
| 139 | * @param i2 long long int two | |
| 140 | * @retval -1 if the left argument is less than the right argument | |
| 141 | * @retval 0 if both arguments are equal | |
| 142 | * @retval 1 if the left argument is greater than the right argument | |
| 143 | */ | |
| 144 | cx_attr_nodiscard | |
| 870 | 145 | CX_EXPORT int cx_vcmp_longlong(long long int i1, long long int i2); |
| 440 | 146 | |
| 147 | /** | |
| 174 | 148 | * Compares two integers of type int16_t. |
| 149 | * | |
| 440 | 150 | * @note the parameters deliberately have type @c void* to be |
| 151 | * compatible with #cx_compare_func without the need of a cast. | |
| 152 | * | |
| 174 | 153 | * @param i1 pointer to int16_t one |
| 154 | * @param i2 pointer to int16_t two | |
| 440 | 155 | * @retval -1 if the left argument is less than the right argument |
| 156 | * @retval 0 if both arguments are equal | |
| 157 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 158 | */ |
| 870 | 159 | cx_attr_nonnull cx_attr_nodiscard |
| 160 | CX_EXPORT int cx_cmp_int16(const void *i1, const void *i2); | |
| 174 | 161 | |
| 162 | /** | |
| 440 | 163 | * Compares two integers of type int16_t. |
| 164 | * | |
| 165 | * @param i1 int16_t one | |
| 166 | * @param i2 int16_t two | |
| 167 | * @retval -1 if the left argument is less than the right argument | |
| 168 | * @retval 0 if both arguments are equal | |
| 169 | * @retval 1 if the left argument is greater than the right argument | |
| 170 | */ | |
| 171 | cx_attr_nodiscard | |
| 870 | 172 | CX_EXPORT int cx_vcmp_int16(int16_t i1, int16_t i2); |
| 440 | 173 | |
| 174 | /** | |
| 174 | 175 | * Compares two integers of type int32_t. |
| 176 | * | |
| 440 | 177 | * @note the parameters deliberately have type @c void* to be |
| 178 | * compatible with #cx_compare_func without the need of a cast. | |
| 179 | * | |
| 174 | 180 | * @param i1 pointer to int32_t one |
| 181 | * @param i2 pointer to int32_t two | |
| 440 | 182 | * @retval -1 if the left argument is less than the right argument |
| 183 | * @retval 0 if both arguments are equal | |
| 184 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 185 | */ |
| 870 | 186 | cx_attr_nonnull cx_attr_nodiscard |
| 187 | CX_EXPORT int cx_cmp_int32(const void *i1, const void *i2); | |
| 174 | 188 | |
| 189 | /** | |
| 440 | 190 | * Compares two integers of type int32_t. |
| 191 | * | |
| 192 | * @param i1 int32_t one | |
| 193 | * @param i2 int32_t two | |
| 194 | * @retval -1 if the left argument is less than the right argument | |
| 195 | * @retval 0 if both arguments are equal | |
| 196 | * @retval 1 if the left argument is greater than the right argument | |
| 197 | */ | |
| 198 | cx_attr_nodiscard | |
| 870 | 199 | CX_EXPORT int cx_vcmp_int32(int32_t i1, int32_t i2); |
| 440 | 200 | |
| 201 | /** | |
| 174 | 202 | * Compares two integers of type int64_t. |
| 203 | * | |
| 440 | 204 | * @note the parameters deliberately have type @c void* to be |
| 205 | * compatible with #cx_compare_func without the need of a cast. | |
| 206 | * | |
| 174 | 207 | * @param i1 pointer to int64_t one |
| 208 | * @param i2 pointer to int64_t two | |
| 440 | 209 | * @retval -1 if the left argument is less than the right argument |
| 210 | * @retval 0 if both arguments are equal | |
| 211 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 212 | */ |
| 870 | 213 | cx_attr_nonnull cx_attr_nodiscard |
| 214 | CX_EXPORT int cx_cmp_int64(const void *i1, const void *i2); | |
| 174 | 215 | |
| 216 | /** | |
| 440 | 217 | * Compares two integers of type int64_t. |
| 218 | * | |
| 219 | * @param i1 int64_t one | |
| 220 | * @param i2 int64_t two | |
| 221 | * @retval -1 if the left argument is less than the right argument | |
| 222 | * @retval 0 if both arguments are equal | |
| 223 | * @retval 1 if the left argument is greater than the right argument | |
| 224 | */ | |
| 225 | cx_attr_nodiscard | |
| 870 | 226 | CX_EXPORT int cx_vcmp_int64(int64_t i1, int64_t i2); |
| 440 | 227 | |
| 228 | /** | |
| 174 | 229 | * Compares two integers of type unsigned int. |
| 230 | * | |
| 440 | 231 | * @note the parameters deliberately have type @c void* to be |
| 232 | * compatible with #cx_compare_func without the need of a cast. | |
| 233 | * | |
| 174 | 234 | * @param i1 pointer to unsigned integer one |
| 235 | * @param i2 pointer to unsigned integer two | |
| 440 | 236 | * @retval -1 if the left argument is less than the right argument |
| 237 | * @retval 0 if both arguments are equal | |
| 238 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 239 | */ |
| 870 | 240 | cx_attr_nonnull cx_attr_nodiscard |
| 241 | CX_EXPORT int cx_cmp_uint(const void *i1, const void *i2); | |
| 174 | 242 | |
| 243 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
244 | * Compares two integers of type unsigned int. |
| 440 | 245 | * |
| 246 | * @param i1 unsigned integer one | |
| 247 | * @param i2 unsigned integer two | |
| 248 | * @retval -1 if the left argument is less than the right argument | |
| 249 | * @retval 0 if both arguments are equal | |
| 250 | * @retval 1 if the left argument is greater than the right argument | |
| 251 | */ | |
| 252 | cx_attr_nodiscard | |
| 870 | 253 | CX_EXPORT int cx_vcmp_uint(unsigned int i1, unsigned int i2); |
| 440 | 254 | |
| 255 | /** | |
| 174 | 256 | * Compares two integers of type unsigned long int. |
| 257 | * | |
| 440 | 258 | * @note the parameters deliberately have type @c void* to be |
| 259 | * compatible with #cx_compare_func without the need of a cast. | |
| 260 | * | |
| 174 | 261 | * @param i1 pointer to unsigned long integer one |
| 262 | * @param i2 pointer to unsigned long integer two | |
| 440 | 263 | * @retval -1 if the left argument is less than the right argument |
| 264 | * @retval 0 if both arguments are equal | |
| 265 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 266 | */ |
| 870 | 267 | cx_attr_nonnull cx_attr_nodiscard |
| 268 | CX_EXPORT int cx_cmp_ulongint(const void *i1, const void *i2); | |
| 174 | 269 | |
| 270 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
271 | * Compares two integers of type unsigned long int. |
| 440 | 272 | * |
| 273 | * @param i1 unsigned long integer one | |
| 274 | * @param i2 unsigned long integer two | |
| 275 | * @retval -1 if the left argument is less than the right argument | |
| 276 | * @retval 0 if both arguments are equal | |
| 277 | * @retval 1 if the left argument is greater than the right argument | |
| 278 | */ | |
| 279 | cx_attr_nodiscard | |
| 870 | 280 | CX_EXPORT int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2); |
| 440 | 281 | |
| 282 | /** | |
| 174 | 283 | * Compares two integers of type unsigned long long. |
| 284 | * | |
| 440 | 285 | * @note the parameters deliberately have type @c void* to be |
| 286 | * compatible with #cx_compare_func without the need of a cast. | |
| 287 | * | |
| 174 | 288 | * @param i1 pointer to unsigned long long one |
| 289 | * @param i2 pointer to unsigned long long two | |
| 440 | 290 | * @retval -1 if the left argument is less than the right argument |
| 291 | * @retval 0 if both arguments are equal | |
| 292 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 293 | */ |
| 870 | 294 | cx_attr_nonnull cx_attr_nodiscard |
| 295 | CX_EXPORT int cx_cmp_ulonglong(const void *i1, const void *i2); | |
| 174 | 296 | |
| 297 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
298 | * Compares two integers of type unsigned long long. |
| 440 | 299 | * |
| 300 | * @param i1 unsigned long long one | |
| 301 | * @param i2 unsigned long long two | |
| 302 | * @retval -1 if the left argument is less than the right argument | |
| 303 | * @retval 0 if both arguments are equal | |
| 304 | * @retval 1 if the left argument is greater than the right argument | |
| 305 | */ | |
| 306 | cx_attr_nodiscard | |
| 870 | 307 | CX_EXPORT int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2); |
| 440 | 308 | |
| 309 | /** | |
| 174 | 310 | * Compares two integers of type uint16_t. |
| 311 | * | |
| 440 | 312 | * @note the parameters deliberately have type @c void* to be |
| 313 | * compatible with #cx_compare_func without the need of a cast. | |
| 314 | * | |
| 174 | 315 | * @param i1 pointer to uint16_t one |
| 316 | * @param i2 pointer to uint16_t two | |
| 440 | 317 | * @retval -1 if the left argument is less than the right argument |
| 318 | * @retval 0 if both arguments are equal | |
| 319 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 320 | */ |
| 870 | 321 | cx_attr_nonnull cx_attr_nodiscard |
| 322 | CX_EXPORT int cx_cmp_uint16(const void *i1, const void *i2); | |
| 174 | 323 | |
| 324 | /** | |
| 440 | 325 | * Compares two integers of type uint16_t. |
| 326 | * | |
| 327 | * @param i1 uint16_t one | |
| 328 | * @param i2 uint16_t two | |
| 329 | * @retval -1 if the left argument is less than the right argument | |
| 330 | * @retval 0 if both arguments are equal | |
| 331 | * @retval 1 if the left argument is greater than the right argument | |
| 332 | */ | |
| 333 | cx_attr_nodiscard | |
| 870 | 334 | CX_EXPORT int cx_vcmp_uint16(uint16_t i1, uint16_t i2); |
| 440 | 335 | |
| 336 | /** | |
| 174 | 337 | * Compares two integers of type uint32_t. |
| 338 | * | |
| 440 | 339 | * @note the parameters deliberately have type @c void* to be |
| 340 | * compatible with #cx_compare_func without the need of a cast. | |
| 341 | * | |
| 174 | 342 | * @param i1 pointer to uint32_t one |
| 343 | * @param i2 pointer to uint32_t two | |
| 440 | 344 | * @retval -1 if the left argument is less than the right argument |
| 345 | * @retval 0 if both arguments are equal | |
| 346 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 347 | */ |
| 870 | 348 | cx_attr_nonnull cx_attr_nodiscard |
| 349 | CX_EXPORT int cx_cmp_uint32(const void *i1, const void *i2); | |
| 174 | 350 | |
| 351 | /** | |
| 440 | 352 | * Compares two integers of type uint32_t. |
| 353 | * | |
| 354 | * @param i1 uint32_t one | |
| 355 | * @param i2 uint32_t two | |
| 356 | * @retval -1 if the left argument is less than the right argument | |
| 357 | * @retval 0 if both arguments are equal | |
| 358 | * @retval 1 if the left argument is greater than the right argument | |
| 359 | */ | |
| 360 | cx_attr_nodiscard | |
| 870 | 361 | CX_EXPORT int cx_vcmp_uint32(uint32_t i1, uint32_t i2); |
| 440 | 362 | |
| 363 | /** | |
| 174 | 364 | * Compares two integers of type uint64_t. |
| 365 | * | |
| 440 | 366 | * @note the parameters deliberately have type @c void* to be |
| 367 | * compatible with #cx_compare_func without the need of a cast. | |
| 368 | * | |
| 174 | 369 | * @param i1 pointer to uint64_t one |
| 370 | * @param i2 pointer to uint64_t two | |
| 440 | 371 | * @retval -1 if the left argument is less than the right argument |
| 372 | * @retval 0 if both arguments are equal | |
| 373 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 374 | */ |
| 870 | 375 | cx_attr_nonnull cx_attr_nodiscard |
| 376 | CX_EXPORT int cx_cmp_uint64(const void *i1, const void *i2); | |
| 174 | 377 | |
| 378 | /** | |
| 440 | 379 | * Compares two integers of type uint64_t. |
| 380 | * | |
| 381 | * @param i1 uint64_t one | |
| 382 | * @param i2 uint64_t two | |
| 383 | * @retval -1 if the left argument is less than the right argument | |
| 384 | * @retval 0 if both arguments are equal | |
| 385 | * @retval 1 if the left argument is greater than the right argument | |
| 386 | */ | |
| 387 | cx_attr_nodiscard | |
| 870 | 388 | CX_EXPORT int cx_vcmp_uint64(uint64_t i1, uint64_t i2); |
| 440 | 389 | |
| 390 | /** | |
| 845 | 391 | * Compares two integers of type size_t. |
| 392 | * | |
| 393 | * @note the parameters deliberately have type @c void* to be | |
| 394 | * compatible with #cx_compare_func without the need of a cast. | |
| 395 | * | |
| 396 | * @param i1 pointer to size_t one | |
| 397 | * @param i2 pointer to size_t two | |
| 398 | * @retval -1 if the left argument is less than the right argument | |
| 399 | * @retval 0 if both arguments are equal | |
| 400 | * @retval 1 if the left argument is greater than the right argument | |
| 401 | */ | |
| 870 | 402 | cx_attr_nonnull cx_attr_nodiscard |
| 403 | CX_EXPORT int cx_cmp_size(const void *i1, const void *i2); | |
| 845 | 404 | |
| 405 | /** | |
| 406 | * Compares two integers of type size_t. | |
| 407 | * | |
| 408 | * @param i1 size_t one | |
| 409 | * @param i2 size_t two | |
| 410 | * @retval -1 if the left argument is less than the right argument | |
| 411 | * @retval 0 if both arguments are equal | |
| 412 | * @retval 1 if the left argument is greater than the right argument | |
| 413 | */ | |
| 414 | cx_attr_nodiscard | |
| 870 | 415 | CX_EXPORT int cx_vcmp_size(size_t i1, size_t i2); |
| 845 | 416 | |
| 417 | /** | |
| 174 | 418 | * Compares two real numbers of type float with precision 1e-6f. |
| 419 | * | |
| 440 | 420 | * @note the parameters deliberately have type @c void* to be |
| 421 | * compatible with #cx_compare_func without the need of a cast. | |
| 422 | * | |
| 174 | 423 | * @param f1 pointer to float one |
| 424 | * @param f2 pointer to float two | |
| 440 | 425 | * @retval -1 if the left argument is less than the right argument |
| 426 | * @retval 0 if both arguments are equal | |
| 427 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 428 | */ |
| 870 | 429 | cx_attr_nonnull cx_attr_nodiscard |
| 430 | CX_EXPORT int cx_cmp_float(const void *f1, const void *f2); | |
| 174 | 431 | |
| 440 | 432 | /** |
| 433 | * Compares two real numbers of type float with precision 1e-6f. | |
| 434 | * | |
| 435 | * @param f1 float one | |
| 436 | * @param f2 float two | |
| 437 | * @retval -1 if the left argument is less than the right argument | |
| 438 | * @retval 0 if both arguments are equal | |
| 439 | * @retval 1 if the left argument is greater than the right argument | |
| 440 | */ | |
| 441 | cx_attr_nodiscard | |
| 870 | 442 | CX_EXPORT int cx_vcmp_float(float f1, float f2); |
| 174 | 443 | |
| 444 | /** | |
| 445 | * Compares two real numbers of type double with precision 1e-14. | |
| 446 | * | |
| 440 | 447 | * @note the parameters deliberately have type @c void* to be |
| 448 | * compatible with #cx_compare_func without the need of a cast. | |
| 449 | * | |
| 174 | 450 | * @param d1 pointer to double one |
| 451 | * @param d2 pointer to double two | |
| 440 | 452 | * @retval -1 if the left argument is less than the right argument |
| 453 | * @retval 0 if both arguments are equal | |
| 454 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 455 | */ |
| 870 | 456 | cx_attr_nonnull cx_attr_nodiscard |
| 457 | CX_EXPORT int cx_cmp_double(const void *d1, const void *d2); | |
| 440 | 458 | |
| 459 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
460 | * Compares two real numbers of type double with precision 1e-14. |
| 440 | 461 | * |
| 462 | * @param d1 double one | |
| 463 | * @param d2 double two | |
| 464 | * @retval -1 if the left argument is less than the right argument | |
| 465 | * @retval 0 if both arguments are equal | |
| 466 | * @retval 1 if the left argument is greater than the right argument | |
| 467 | */ | |
| 468 | cx_attr_nodiscard | |
| 870 | 469 | CX_EXPORT int cx_vcmp_double(double d1, double d2); |
| 174 | 470 | |
| 471 | /** | |
| 472 | * Compares the integer representation of two pointers. | |
| 473 | * | |
| 440 | 474 | * @note the parameters deliberately have type @c void* to be |
| 475 | * compatible with #cx_compare_func without the need of a cast. | |
| 476 | * | |
| 324 | 477 | * @param ptr1 pointer to pointer one (const intptr_t*) |
| 478 | * @param ptr2 pointer to pointer two (const intptr_t*) | |
| 440 | 479 | * @retval -1 if the left argument is less than the right argument |
| 480 | * @retval 0 if both arguments are equal | |
| 481 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 482 | */ |
| 870 | 483 | cx_attr_nonnull cx_attr_nodiscard |
| 484 | CX_EXPORT int cx_cmp_intptr(const void *ptr1, const void *ptr2); | |
| 440 | 485 | |
| 486 | /** | |
| 487 | * Compares the integer representation of two pointers. | |
| 488 | * | |
| 489 | * @param ptr1 pointer one | |
| 490 | * @param ptr2 pointer two | |
| 491 | * @retval -1 if the left argument is less than the right argument | |
| 492 | * @retval 0 if both arguments are equal | |
| 493 | * @retval 1 if the left argument is greater than the right argument | |
| 494 | */ | |
| 495 | cx_attr_nodiscard | |
| 870 | 496 | CX_EXPORT int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2); |
| 174 | 497 | |
| 498 | /** | |
| 499 | * Compares the unsigned integer representation of two pointers. | |
| 500 | * | |
| 440 | 501 | * @note the parameters deliberately have type @c void* to be |
| 502 | * compatible with #cx_compare_func without the need of a cast. | |
| 503 | * | |
| 324 | 504 | * @param ptr1 pointer to pointer one (const uintptr_t*) |
| 505 | * @param ptr2 pointer to pointer two (const uintptr_t*) | |
| 440 | 506 | * @retval -1 if the left argument is less than the right argument |
| 507 | * @retval 0 if both arguments are equal | |
| 508 | * @retval 1 if the left argument is greater than the right argument | |
| 174 | 509 | */ |
| 870 | 510 | cx_attr_nonnull cx_attr_nodiscard |
| 511 | CX_EXPORT int cx_cmp_uintptr(const void *ptr1, const void *ptr2); | |
| 440 | 512 | |
| 513 | /** | |
| 514 | * Compares the unsigned integer representation of two pointers. | |
| 515 | * | |
| 516 | * @param ptr1 pointer one | |
| 517 | * @param ptr2 pointer two | |
| 518 | * @retval -1 if the left argument is less than the right argument | |
| 519 | * @retval 0 if both arguments are equal | |
| 520 | * @retval 1 if the left argument is greater than the right argument | |
| 521 | */ | |
| 522 | cx_attr_nodiscard | |
| 870 | 523 | CX_EXPORT int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2); |
| 174 | 524 | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
525 | /** |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
526 | * Compares the pointers specified in the arguments without dereferencing. |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
527 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
528 | * @param ptr1 pointer one |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
529 | * @param ptr2 pointer two |
| 440 | 530 | * @retval -1 if the left argument is less than the right argument |
| 531 | * @retval 0 if both arguments are equal | |
| 532 | * @retval 1 if the left argument is greater than the right argument | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
533 | */ |
| 870 | 534 | cx_attr_nonnull cx_attr_nodiscard |
| 535 | CX_EXPORT int cx_cmp_ptr(const void *ptr1, const void *ptr2); | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
536 | |
| 1016 | 537 | /** |
| 538 | * A @c cx_compare_func2 compatible wrapper for @c memcmp(). | |
| 539 | * | |
| 540 | * @param ptr1 pointer one | |
| 541 | * @param ptr2 pointer two | |
| 542 | * @param n (@c size_t*) a pointer to the length | |
| 543 | * @return the result of @c memcmp() | |
| 544 | */ | |
| 545 | cx_attr_nonnull cx_attr_nodiscard | |
| 546 | CX_EXPORT int cx_acmp_memcmp(const void *ptr1, const void *ptr2, void *n); | |
| 547 | ||
| 548 | /** Wraps a compare function for cx_acmp_wrap. */ | |
| 549 | typedef struct { | |
| 550 | /** The wrapped compare function */ | |
| 551 | cx_compare_func cmp; | |
| 552 | } cx_compare_func_wrapper; | |
| 553 | ||
| 554 | /** | |
| 555 | * A @c cx_compare_func2 wrapper for a @c cx_compare_func(). | |
| 556 | * | |
| 557 | * This is not strictly compatible with a @c cx_compare_func2 because | |
| 558 | * ISO C does not define conversions between function and object pointers. | |
| 559 | * | |
| 560 | * But it works on all tested platforms to cast a pointer to this function to | |
| 561 | * a @c cx_compare_func2. | |
| 562 | * | |
| 563 | * @param ptr1 pointer one | |
| 564 | * @param ptr2 pointer two | |
| 565 | * @param cmp_wrapper a pointer to a @c cx_compare_func_wrapper | |
| 566 | * @return the result of the invoked compare function | |
| 567 | * @see cx_compare_func_wrapper_s | |
| 568 | */ | |
| 569 | cx_attr_nonnull cx_attr_nodiscard | |
| 570 | CX_EXPORT int cx_acmp_wrap(const void *ptr1, const void *ptr2, void* cmp_wrapper); | |
| 571 | ||
| 174 | 572 | #ifdef __cplusplus |
| 573 | } // extern "C" | |
| 574 | #endif | |
| 575 | ||
| 576 | #endif //UCX_COMPARE_H |