src/cx/compare.h

changeset 1180
4c3a69b9723a
parent 1092
8a35119d1f01
child 1181
183bf43aa9b9
equal deleted inserted replaced
1179:ca4c6f590a08 1180:4c3a69b9723a
54 * can be used, but they are NOT compatible with this function 54 * can be used, but they are NOT compatible with this function
55 * pointer. 55 * pointer.
56 */ 56 */
57 cx_attr_nonnull 57 cx_attr_nonnull
58 cx_attr_nodiscard 58 cx_attr_nodiscard
59 cx_attr_export
59 typedef int (*cx_compare_func)( 60 typedef int (*cx_compare_func)(
60 const void *left, 61 const void *left,
61 const void *right 62 const void *right
62 ); 63 );
63 64
73 * @retval 0 if both arguments are equal 74 * @retval 0 if both arguments are equal
74 * @retval 1 if the left argument is greater than the right argument 75 * @retval 1 if the left argument is greater than the right argument
75 */ 76 */
76 cx_attr_nonnull 77 cx_attr_nonnull
77 cx_attr_nodiscard 78 cx_attr_nodiscard
79 cx_attr_export
78 int cx_cmp_int(const void *i1, const void *i2); 80 int cx_cmp_int(const void *i1, const void *i2);
79 81
80 /** 82 /**
81 * Compares two ints. 83 * Compares two ints.
82 * 84 *
85 * @retval -1 if the left argument is less than the right argument 87 * @retval -1 if the left argument is less than the right argument
86 * @retval 0 if both arguments are equal 88 * @retval 0 if both arguments are equal
87 * @retval 1 if the left argument is greater than the right argument 89 * @retval 1 if the left argument is greater than the right argument
88 */ 90 */
89 cx_attr_nodiscard 91 cx_attr_nodiscard
92 cx_attr_export
90 int cx_vcmp_int(int i1, int i2); 93 int cx_vcmp_int(int i1, int i2);
91 94
92 /** 95 /**
93 * Compares two integers of type long int. 96 * Compares two integers of type long int.
94 * 97 *
101 * @retval 0 if both arguments are equal 104 * @retval 0 if both arguments are equal
102 * @retval 1 if the left argument is greater than the right argument 105 * @retval 1 if the left argument is greater than the right argument
103 */ 106 */
104 cx_attr_nonnull 107 cx_attr_nonnull
105 cx_attr_nodiscard 108 cx_attr_nodiscard
109 cx_attr_export
106 int cx_cmp_longint(const void *i1, const void *i2); 110 int cx_cmp_longint(const void *i1, const void *i2);
107 111
108 /** 112 /**
109 * Compares two long ints. 113 * Compares two long ints.
110 * 114 *
113 * @retval -1 if the left argument is less than the right argument 117 * @retval -1 if the left argument is less than the right argument
114 * @retval 0 if both arguments are equal 118 * @retval 0 if both arguments are equal
115 * @retval 1 if the left argument is greater than the right argument 119 * @retval 1 if the left argument is greater than the right argument
116 */ 120 */
117 cx_attr_nodiscard 121 cx_attr_nodiscard
122 cx_attr_export
118 int cx_vcmp_longint(long int i1, long int i2); 123 int cx_vcmp_longint(long int i1, long int i2);
119 124
120 /** 125 /**
121 * Compares two integers of type long long. 126 * Compares two integers of type long long.
122 * 127 *
129 * @retval 0 if both arguments are equal 134 * @retval 0 if both arguments are equal
130 * @retval 1 if the left argument is greater than the right argument 135 * @retval 1 if the left argument is greater than the right argument
131 */ 136 */
132 cx_attr_nonnull 137 cx_attr_nonnull
133 cx_attr_nodiscard 138 cx_attr_nodiscard
139 cx_attr_export
134 int cx_cmp_longlong(const void *i1, const void *i2); 140 int cx_cmp_longlong(const void *i1, const void *i2);
135 141
136 /** 142 /**
137 * Compares twolong long ints. 143 * Compares twolong long ints.
138 * 144 *
141 * @retval -1 if the left argument is less than the right argument 147 * @retval -1 if the left argument is less than the right argument
142 * @retval 0 if both arguments are equal 148 * @retval 0 if both arguments are equal
143 * @retval 1 if the left argument is greater than the right argument 149 * @retval 1 if the left argument is greater than the right argument
144 */ 150 */
145 cx_attr_nodiscard 151 cx_attr_nodiscard
152 cx_attr_export
146 int cx_vcmp_longlong(long long int i1, long long int i2); 153 int cx_vcmp_longlong(long long int i1, long long int i2);
147 154
148 /** 155 /**
149 * Compares two integers of type int16_t. 156 * Compares two integers of type int16_t.
150 * 157 *
157 * @retval 0 if both arguments are equal 164 * @retval 0 if both arguments are equal
158 * @retval 1 if the left argument is greater than the right argument 165 * @retval 1 if the left argument is greater than the right argument
159 */ 166 */
160 cx_attr_nonnull 167 cx_attr_nonnull
161 cx_attr_nodiscard 168 cx_attr_nodiscard
169 cx_attr_export
162 int cx_cmp_int16(const void *i1, const void *i2); 170 int cx_cmp_int16(const void *i1, const void *i2);
163 171
164 /** 172 /**
165 * Compares two integers of type int16_t. 173 * Compares two integers of type int16_t.
166 * 174 *
169 * @retval -1 if the left argument is less than the right argument 177 * @retval -1 if the left argument is less than the right argument
170 * @retval 0 if both arguments are equal 178 * @retval 0 if both arguments are equal
171 * @retval 1 if the left argument is greater than the right argument 179 * @retval 1 if the left argument is greater than the right argument
172 */ 180 */
173 cx_attr_nodiscard 181 cx_attr_nodiscard
182 cx_attr_export
174 int cx_vcmp_int16(int16_t i1, int16_t i2); 183 int cx_vcmp_int16(int16_t i1, int16_t i2);
175 184
176 /** 185 /**
177 * Compares two integers of type int32_t. 186 * Compares two integers of type int32_t.
178 * 187 *
185 * @retval 0 if both arguments are equal 194 * @retval 0 if both arguments are equal
186 * @retval 1 if the left argument is greater than the right argument 195 * @retval 1 if the left argument is greater than the right argument
187 */ 196 */
188 cx_attr_nonnull 197 cx_attr_nonnull
189 cx_attr_nodiscard 198 cx_attr_nodiscard
199 cx_attr_export
190 int cx_cmp_int32(const void *i1, const void *i2); 200 int cx_cmp_int32(const void *i1, const void *i2);
191 201
192 /** 202 /**
193 * Compares two integers of type int32_t. 203 * Compares two integers of type int32_t.
194 * 204 *
197 * @retval -1 if the left argument is less than the right argument 207 * @retval -1 if the left argument is less than the right argument
198 * @retval 0 if both arguments are equal 208 * @retval 0 if both arguments are equal
199 * @retval 1 if the left argument is greater than the right argument 209 * @retval 1 if the left argument is greater than the right argument
200 */ 210 */
201 cx_attr_nodiscard 211 cx_attr_nodiscard
212 cx_attr_export
202 int cx_vcmp_int32(int32_t i1, int32_t i2); 213 int cx_vcmp_int32(int32_t i1, int32_t i2);
203 214
204 /** 215 /**
205 * Compares two integers of type int64_t. 216 * Compares two integers of type int64_t.
206 * 217 *
213 * @retval 0 if both arguments are equal 224 * @retval 0 if both arguments are equal
214 * @retval 1 if the left argument is greater than the right argument 225 * @retval 1 if the left argument is greater than the right argument
215 */ 226 */
216 cx_attr_nonnull 227 cx_attr_nonnull
217 cx_attr_nodiscard 228 cx_attr_nodiscard
229 cx_attr_export
218 int cx_cmp_int64(const void *i1, const void *i2); 230 int cx_cmp_int64(const void *i1, const void *i2);
219 231
220 /** 232 /**
221 * Compares two integers of type int64_t. 233 * Compares two integers of type int64_t.
222 * 234 *
225 * @retval -1 if the left argument is less than the right argument 237 * @retval -1 if the left argument is less than the right argument
226 * @retval 0 if both arguments are equal 238 * @retval 0 if both arguments are equal
227 * @retval 1 if the left argument is greater than the right argument 239 * @retval 1 if the left argument is greater than the right argument
228 */ 240 */
229 cx_attr_nodiscard 241 cx_attr_nodiscard
242 cx_attr_export
230 int cx_vcmp_int64(int64_t i1, int64_t i2); 243 int cx_vcmp_int64(int64_t i1, int64_t i2);
231 244
232 /** 245 /**
233 * Compares two integers of type unsigned int. 246 * Compares two integers of type unsigned int.
234 * 247 *
241 * @retval 0 if both arguments are equal 254 * @retval 0 if both arguments are equal
242 * @retval 1 if the left argument is greater than the right argument 255 * @retval 1 if the left argument is greater than the right argument
243 */ 256 */
244 cx_attr_nonnull 257 cx_attr_nonnull
245 cx_attr_nodiscard 258 cx_attr_nodiscard
259 cx_attr_export
246 int cx_cmp_uint(const void *i1, const void *i2); 260 int cx_cmp_uint(const void *i1, const void *i2);
247 261
248 /** 262 /**
249 * Compares two unsigned ints. 263 * Compares two unsigned ints.
250 * 264 *
253 * @retval -1 if the left argument is less than the right argument 267 * @retval -1 if the left argument is less than the right argument
254 * @retval 0 if both arguments are equal 268 * @retval 0 if both arguments are equal
255 * @retval 1 if the left argument is greater than the right argument 269 * @retval 1 if the left argument is greater than the right argument
256 */ 270 */
257 cx_attr_nodiscard 271 cx_attr_nodiscard
272 cx_attr_export
258 int cx_vcmp_uint(unsigned int i1, unsigned int i2); 273 int cx_vcmp_uint(unsigned int i1, unsigned int i2);
259 274
260 /** 275 /**
261 * Compares two integers of type unsigned long int. 276 * Compares two integers of type unsigned long int.
262 * 277 *
269 * @retval 0 if both arguments are equal 284 * @retval 0 if both arguments are equal
270 * @retval 1 if the left argument is greater than the right argument 285 * @retval 1 if the left argument is greater than the right argument
271 */ 286 */
272 cx_attr_nonnull 287 cx_attr_nonnull
273 cx_attr_nodiscard 288 cx_attr_nodiscard
289 cx_attr_export
274 int cx_cmp_ulongint(const void *i1, const void *i2); 290 int cx_cmp_ulongint(const void *i1, const void *i2);
275 291
276 /** 292 /**
277 * Compares two unsigned long ints. 293 * Compares two unsigned long ints.
278 * 294 *
281 * @retval -1 if the left argument is less than the right argument 297 * @retval -1 if the left argument is less than the right argument
282 * @retval 0 if both arguments are equal 298 * @retval 0 if both arguments are equal
283 * @retval 1 if the left argument is greater than the right argument 299 * @retval 1 if the left argument is greater than the right argument
284 */ 300 */
285 cx_attr_nodiscard 301 cx_attr_nodiscard
302 cx_attr_export
286 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2); 303 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2);
287 304
288 /** 305 /**
289 * Compares two integers of type unsigned long long. 306 * Compares two integers of type unsigned long long.
290 * 307 *
297 * @retval 0 if both arguments are equal 314 * @retval 0 if both arguments are equal
298 * @retval 1 if the left argument is greater than the right argument 315 * @retval 1 if the left argument is greater than the right argument
299 */ 316 */
300 cx_attr_nonnull 317 cx_attr_nonnull
301 cx_attr_nodiscard 318 cx_attr_nodiscard
319 cx_attr_export
302 int cx_cmp_ulonglong(const void *i1, const void *i2); 320 int cx_cmp_ulonglong(const void *i1, const void *i2);
303 321
304 /** 322 /**
305 * Compares two unsigned long long ints. 323 * Compares two unsigned long long ints.
306 * 324 *
309 * @retval -1 if the left argument is less than the right argument 327 * @retval -1 if the left argument is less than the right argument
310 * @retval 0 if both arguments are equal 328 * @retval 0 if both arguments are equal
311 * @retval 1 if the left argument is greater than the right argument 329 * @retval 1 if the left argument is greater than the right argument
312 */ 330 */
313 cx_attr_nodiscard 331 cx_attr_nodiscard
332 cx_attr_export
314 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2); 333 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2);
315 334
316 /** 335 /**
317 * Compares two integers of type uint16_t. 336 * Compares two integers of type uint16_t.
318 * 337 *
325 * @retval 0 if both arguments are equal 344 * @retval 0 if both arguments are equal
326 * @retval 1 if the left argument is greater than the right argument 345 * @retval 1 if the left argument is greater than the right argument
327 */ 346 */
328 cx_attr_nonnull 347 cx_attr_nonnull
329 cx_attr_nodiscard 348 cx_attr_nodiscard
349 cx_attr_export
330 int cx_cmp_uint16(const void *i1, const void *i2); 350 int cx_cmp_uint16(const void *i1, const void *i2);
331 351
332 /** 352 /**
333 * Compares two integers of type uint16_t. 353 * Compares two integers of type uint16_t.
334 * 354 *
337 * @retval -1 if the left argument is less than the right argument 357 * @retval -1 if the left argument is less than the right argument
338 * @retval 0 if both arguments are equal 358 * @retval 0 if both arguments are equal
339 * @retval 1 if the left argument is greater than the right argument 359 * @retval 1 if the left argument is greater than the right argument
340 */ 360 */
341 cx_attr_nodiscard 361 cx_attr_nodiscard
362 cx_attr_export
342 int cx_vcmp_uint16(uint16_t i1, uint16_t i2); 363 int cx_vcmp_uint16(uint16_t i1, uint16_t i2);
343 364
344 /** 365 /**
345 * Compares two integers of type uint32_t. 366 * Compares two integers of type uint32_t.
346 * 367 *
353 * @retval 0 if both arguments are equal 374 * @retval 0 if both arguments are equal
354 * @retval 1 if the left argument is greater than the right argument 375 * @retval 1 if the left argument is greater than the right argument
355 */ 376 */
356 cx_attr_nonnull 377 cx_attr_nonnull
357 cx_attr_nodiscard 378 cx_attr_nodiscard
379 cx_attr_export
358 int cx_cmp_uint32(const void *i1, const void *i2); 380 int cx_cmp_uint32(const void *i1, const void *i2);
359 381
360 /** 382 /**
361 * Compares two integers of type uint32_t. 383 * Compares two integers of type uint32_t.
362 * 384 *
365 * @retval -1 if the left argument is less than the right argument 387 * @retval -1 if the left argument is less than the right argument
366 * @retval 0 if both arguments are equal 388 * @retval 0 if both arguments are equal
367 * @retval 1 if the left argument is greater than the right argument 389 * @retval 1 if the left argument is greater than the right argument
368 */ 390 */
369 cx_attr_nodiscard 391 cx_attr_nodiscard
392 cx_attr_export
370 int cx_vcmp_uint32(uint32_t i1, uint32_t i2); 393 int cx_vcmp_uint32(uint32_t i1, uint32_t i2);
371 394
372 /** 395 /**
373 * Compares two integers of type uint64_t. 396 * Compares two integers of type uint64_t.
374 * 397 *
381 * @retval 0 if both arguments are equal 404 * @retval 0 if both arguments are equal
382 * @retval 1 if the left argument is greater than the right argument 405 * @retval 1 if the left argument is greater than the right argument
383 */ 406 */
384 cx_attr_nonnull 407 cx_attr_nonnull
385 cx_attr_nodiscard 408 cx_attr_nodiscard
409 cx_attr_export
386 int cx_cmp_uint64(const void *i1, const void *i2); 410 int cx_cmp_uint64(const void *i1, const void *i2);
387 411
388 /** 412 /**
389 * Compares two integers of type uint64_t. 413 * Compares two integers of type uint64_t.
390 * 414 *
393 * @retval -1 if the left argument is less than the right argument 417 * @retval -1 if the left argument is less than the right argument
394 * @retval 0 if both arguments are equal 418 * @retval 0 if both arguments are equal
395 * @retval 1 if the left argument is greater than the right argument 419 * @retval 1 if the left argument is greater than the right argument
396 */ 420 */
397 cx_attr_nodiscard 421 cx_attr_nodiscard
422 cx_attr_export
398 int cx_vcmp_uint64(uint64_t i1, uint64_t i2); 423 int cx_vcmp_uint64(uint64_t i1, uint64_t i2);
399 424
400 /** 425 /**
401 * Compares two real numbers of type float with precision 1e-6f. 426 * Compares two real numbers of type float with precision 1e-6f.
402 * 427 *
409 * @retval 0 if both arguments are equal 434 * @retval 0 if both arguments are equal
410 * @retval 1 if the left argument is greater than the right argument 435 * @retval 1 if the left argument is greater than the right argument
411 */ 436 */
412 cx_attr_nonnull 437 cx_attr_nonnull
413 cx_attr_nodiscard 438 cx_attr_nodiscard
439 cx_attr_export
414 int cx_cmp_float(const void *f1, const void *f2); 440 int cx_cmp_float(const void *f1, const void *f2);
415 441
416 /** 442 /**
417 * Compares two real numbers of type float with precision 1e-6f. 443 * Compares two real numbers of type float with precision 1e-6f.
418 * 444 *
421 * @retval -1 if the left argument is less than the right argument 447 * @retval -1 if the left argument is less than the right argument
422 * @retval 0 if both arguments are equal 448 * @retval 0 if both arguments are equal
423 * @retval 1 if the left argument is greater than the right argument 449 * @retval 1 if the left argument is greater than the right argument
424 */ 450 */
425 cx_attr_nodiscard 451 cx_attr_nodiscard
452 cx_attr_export
426 int cx_vcmp_float(float f1, float f2); 453 int cx_vcmp_float(float f1, float f2);
427 454
428 /** 455 /**
429 * Compares two real numbers of type double with precision 1e-14. 456 * Compares two real numbers of type double with precision 1e-14.
430 * 457 *
437 * @retval 0 if both arguments are equal 464 * @retval 0 if both arguments are equal
438 * @retval 1 if the left argument is greater than the right argument 465 * @retval 1 if the left argument is greater than the right argument
439 */ 466 */
440 cx_attr_nonnull 467 cx_attr_nonnull
441 cx_attr_nodiscard 468 cx_attr_nodiscard
469 cx_attr_export
442 int cx_cmp_double(const void *d1, const void *d2); 470 int cx_cmp_double(const void *d1, const void *d2);
443 471
444 /** 472 /**
445 * Convenience function 473 * Convenience function
446 * 474 *
449 * @retval -1 if the left argument is less than the right argument 477 * @retval -1 if the left argument is less than the right argument
450 * @retval 0 if both arguments are equal 478 * @retval 0 if both arguments are equal
451 * @retval 1 if the left argument is greater than the right argument 479 * @retval 1 if the left argument is greater than the right argument
452 */ 480 */
453 cx_attr_nodiscard 481 cx_attr_nodiscard
482 cx_attr_export
454 int cx_vcmp_double(double d1, double d2); 483 int cx_vcmp_double(double d1, double d2);
455 484
456 /** 485 /**
457 * Compares the integer representation of two pointers. 486 * Compares the integer representation of two pointers.
458 * 487 *
465 * @retval 0 if both arguments are equal 494 * @retval 0 if both arguments are equal
466 * @retval 1 if the left argument is greater than the right argument 495 * @retval 1 if the left argument is greater than the right argument
467 */ 496 */
468 cx_attr_nonnull 497 cx_attr_nonnull
469 cx_attr_nodiscard 498 cx_attr_nodiscard
499 cx_attr_export
470 int cx_cmp_intptr(const void *ptr1, const void *ptr2); 500 int cx_cmp_intptr(const void *ptr1, const void *ptr2);
471 501
472 /** 502 /**
473 * Compares the integer representation of two pointers. 503 * Compares the integer representation of two pointers.
474 * 504 *
477 * @retval -1 if the left argument is less than the right argument 507 * @retval -1 if the left argument is less than the right argument
478 * @retval 0 if both arguments are equal 508 * @retval 0 if both arguments are equal
479 * @retval 1 if the left argument is greater than the right argument 509 * @retval 1 if the left argument is greater than the right argument
480 */ 510 */
481 cx_attr_nodiscard 511 cx_attr_nodiscard
512 cx_attr_export
482 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2); 513 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2);
483 514
484 /** 515 /**
485 * Compares the unsigned integer representation of two pointers. 516 * Compares the unsigned integer representation of two pointers.
486 * 517 *
493 * @retval 0 if both arguments are equal 524 * @retval 0 if both arguments are equal
494 * @retval 1 if the left argument is greater than the right argument 525 * @retval 1 if the left argument is greater than the right argument
495 */ 526 */
496 cx_attr_nonnull 527 cx_attr_nonnull
497 cx_attr_nodiscard 528 cx_attr_nodiscard
529 cx_attr_export
498 int cx_cmp_uintptr(const void *ptr1, const void *ptr2); 530 int cx_cmp_uintptr(const void *ptr1, const void *ptr2);
499 531
500 /** 532 /**
501 * Compares the unsigned integer representation of two pointers. 533 * Compares the unsigned integer representation of two pointers.
502 * 534 *
505 * @retval -1 if the left argument is less than the right argument 537 * @retval -1 if the left argument is less than the right argument
506 * @retval 0 if both arguments are equal 538 * @retval 0 if both arguments are equal
507 * @retval 1 if the left argument is greater than the right argument 539 * @retval 1 if the left argument is greater than the right argument
508 */ 540 */
509 cx_attr_nodiscard 541 cx_attr_nodiscard
542 cx_attr_export
510 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2); 543 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2);
511 544
512 /** 545 /**
513 * Compares the pointers specified in the arguments without de-referencing. 546 * Compares the pointers specified in the arguments without de-referencing.
514 * 547 *
518 * @retval 0 if both arguments are equal 551 * @retval 0 if both arguments are equal
519 * @retval 1 if the left argument is greater than the right argument 552 * @retval 1 if the left argument is greater than the right argument
520 */ 553 */
521 cx_attr_nonnull 554 cx_attr_nonnull
522 cx_attr_nodiscard 555 cx_attr_nodiscard
556 cx_attr_export
523 int cx_cmp_ptr(const void *ptr1, const void *ptr2); 557 int cx_cmp_ptr(const void *ptr1, const void *ptr2);
524 558
525 #ifdef __cplusplus 559 #ifdef __cplusplus
526 } // extern "C" 560 } // extern "C"
527 #endif 561 #endif

mercurial