| 1 # Compare Functions |
1 # Compare Functions |
| 2 |
2 |
| 3 <warning> |
3 The `compare.h` header file contains a collection of compare functions for various primitive types. |
| 4 Outdated - Rewrite! |
|
| 5 </warning> |
|
| 6 |
4 |
| 7 This header file contains a collection of compare functions for various data types. |
5 They come in two flavors: |
| 8 Their signatures are designed to be compatible with the `cx_compare_func` function pointer type. |
6 - prefixed with `cx_vcmp` they are taking the values directly as arguments |
| |
7 - prefixed with `cx_cmp` the signature is designed to be compatible with the `cx_compare_func` function pointer type. |
| 9 |
8 |
| 10 ## Undocumented Symbols (TODO) |
9 ## Examples |
| 11 ### cx_cmp_double |
10 |
| 12 ### cx_cmp_float |
11 In the following example we use `cx_cmp_int32` as compare function for a `CxList` of `int32_t` values. |
| 13 ### cx_cmp_int |
12 |
| 14 ### cx_cmp_int16 |
13 ```C |
| 15 ### cx_cmp_int32 |
14 CxList *list = cxArrayListCreate( |
| 16 ### cx_cmp_int64 |
15 cxDefaultAllocator, // use the default stdlib allocator |
| 17 ### cx_cmp_intptr |
16 cx_cmp_int32, // the compare function for the elements |
| 18 ### cx_cmp_longint |
17 sizeof(int32_t), // the size of one element |
| 19 ### cx_cmp_longlong |
18 256 // reseve space for 256 elements |
| 20 ### cx_cmp_ptr |
19 ); |
| 21 ### cx_cmp_uint |
20 ``` |
| 22 ### cx_cmp_uint16 |
21 |
| 23 ### cx_cmp_uint32 |
22 In the next example we simply want to compare two `double` values with rounding tolerance. |
| 24 ### cx_cmp_uint64 |
23 Note how the use of the `cx_vcmp` flavour makes it unnecessary to store the literal in a variable just to be able to take an address. |
| 25 ### cx_cmp_uintptr |
24 ```C |
| 26 ### cx_cmp_ulongint |
25 double x = ... |
| 27 ### cx_cmp_ulonglong |
26 |
| 28 ### cx_vcmp_double |
27 if (0 == cx_vcmp(x, 47.11)) { |
| 29 ### cx_vcmp_float |
28 // do something when equal (except tolerance) |
| 30 ### cx_vcmp_int |
29 } |
| 31 ### cx_vcmp_int16 |
30 ``` |
| 32 ### cx_vcmp_int32 |
31 |
| 33 ### cx_vcmp_int64 |
32 ## List of Functions |
| 34 ### cx_vcmp_intptr |
33 |
| 35 ### cx_vcmp_longint |
34 ```C |
| 36 ### cx_vcmp_longlong |
35 // Value Flavour |
| 37 ### cx_vcmp_uint |
36 cx_vcmp_double |
| 38 ### cx_vcmp_uint16 |
37 cx_vcmp_float |
| 39 ### cx_vcmp_uint32 |
38 cx_vcmp_int |
| 40 ### cx_vcmp_uint64 |
39 cx_vcmp_int16 |
| 41 ### cx_vcmp_uintptr |
40 cx_vcmp_int32 |
| 42 ### cx_vcmp_ulongint |
41 cx_vcmp_int64 |
| 43 ### cx_vcmp_ulonglong |
42 cx_vcmp_intptr |
| |
43 cx_vcmp_longint |
| |
44 cx_vcmp_longlong |
| |
45 cx_vcmp_uint |
| |
46 cx_vcmp_uint16 |
| |
47 cx_vcmp_uint32 |
| |
48 cx_vcmp_uint64 |
| |
49 cx_vcmp_uintptr |
| |
50 cx_vcmp_ulongint |
| |
51 cx_vcmp_ulonglong |
| |
52 |
| |
53 // Pointer Flavour |
| |
54 cx_cmp_double |
| |
55 cx_cmp_float |
| |
56 cx_cmp_int |
| |
57 cx_cmp_int16 |
| |
58 cx_cmp_int32 |
| |
59 cx_cmp_int64 |
| |
60 cx_cmp_intptr |
| |
61 cx_cmp_longint |
| |
62 cx_cmp_longlong |
| |
63 cx_cmp_ptr |
| |
64 cx_cmp_uint |
| |
65 cx_cmp_uint16 |
| |
66 cx_cmp_uint32 |
| |
67 cx_cmp_uint64 |
| |
68 cx_cmp_uintptr |
| |
69 cx_cmp_ulongint |
| |
70 cx_cmp_ulonglong |
| |
71 ``` |
| |
72 |
| |
73 <seealso> |
| |
74 <category ref="apidoc"> |
| |
75 <a href="https://ucx.sourceforge.io/api/compare_8h.html">compare.h</a> |
| |
76 </category> |
| |
77 </seealso> |