Wed, 17 Dec 2025 19:05:50 +0100
huge refactoring of collections to add support for 3-arg compare functions
| 601 | 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 | ||
| 29 | #include "cx/compare.h" | |
| 30 | ||
| 31 | #include <math.h> | |
|
1618
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
32 | #include <string.h> |
| 601 | 33 | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
34 | int cx_vcmp_int(int a, int b) { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
35 | if (a == b) { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
36 | return 0; |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
37 | } else { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
38 | return a < b ? -1 : 1; |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
39 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
40 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
41 | |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
42 | int cx_cmp_int(const void *i1, const void *i2) { |
| 678 | 43 | int a = *((const int *) i1); |
| 44 | int b = *((const int *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
45 | return cx_vcmp_int(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
46 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
47 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
48 | int cx_vcmp_longint(long int a, long int b) { |
| 601 | 49 | if (a == b) { |
| 50 | return 0; | |
| 51 | } else { | |
| 52 | return a < b ? -1 : 1; | |
| 53 | } | |
| 54 | } | |
| 55 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
56 | int cx_cmp_longint(const void *i1, const void *i2) { |
| 678 | 57 | long int a = *((const long int *) i1); |
| 58 | long int b = *((const long int *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
59 | return cx_vcmp_longint(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
60 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
61 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
62 | int cx_vcmp_longlong(long long a, long long b) { |
| 601 | 63 | if (a == b) { |
| 64 | return 0; | |
| 65 | } else { | |
| 66 | return a < b ? -1 : 1; | |
| 67 | } | |
| 68 | } | |
| 69 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
70 | int cx_cmp_longlong(const void *i1, const void *i2) { |
| 678 | 71 | long long a = *((const long long *) i1); |
| 72 | long long b = *((const long long *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
73 | return cx_vcmp_longlong(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
74 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
75 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
76 | int cx_vcmp_int16(int16_t a, int16_t b) { |
| 601 | 77 | if (a == b) { |
| 78 | return 0; | |
| 79 | } else { | |
| 80 | return a < b ? -1 : 1; | |
| 81 | } | |
| 82 | } | |
| 83 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
84 | int cx_cmp_int16(const void *i1, const void *i2) { |
| 678 | 85 | int16_t a = *((const int16_t *) i1); |
| 86 | int16_t b = *((const int16_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
87 | return cx_vcmp_int16(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
88 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
89 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
90 | int cx_vcmp_int32(int32_t a, int32_t b) { |
| 601 | 91 | if (a == b) { |
| 92 | return 0; | |
| 93 | } else { | |
| 94 | return a < b ? -1 : 1; | |
| 95 | } | |
| 96 | } | |
| 97 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
98 | int cx_cmp_int32(const void *i1, const void *i2) { |
| 678 | 99 | int32_t a = *((const int32_t *) i1); |
| 100 | int32_t b = *((const int32_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
101 | return cx_vcmp_int32(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
102 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
103 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
104 | int cx_vcmp_int64(int64_t a, int64_t b) { |
| 601 | 105 | if (a == b) { |
| 106 | return 0; | |
| 107 | } else { | |
| 108 | return a < b ? -1 : 1; | |
| 109 | } | |
| 110 | } | |
| 111 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
112 | int cx_cmp_int64(const void *i1, const void *i2) { |
| 678 | 113 | int64_t a = *((const int64_t *) i1); |
| 114 | int64_t b = *((const int64_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
115 | return cx_vcmp_int64(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
116 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
117 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
118 | int cx_vcmp_uint(unsigned int a, unsigned int b) { |
| 601 | 119 | if (a == b) { |
| 120 | return 0; | |
| 121 | } else { | |
| 122 | return a < b ? -1 : 1; | |
| 123 | } | |
| 124 | } | |
| 125 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
126 | int cx_cmp_uint(const void *i1, const void *i2) { |
| 678 | 127 | unsigned int a = *((const unsigned int *) i1); |
| 128 | unsigned int b = *((const unsigned int *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
129 | return cx_vcmp_uint(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
130 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
131 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
132 | int cx_vcmp_ulongint(unsigned long int a, unsigned long int b) { |
| 601 | 133 | if (a == b) { |
| 134 | return 0; | |
| 135 | } else { | |
| 136 | return a < b ? -1 : 1; | |
| 137 | } | |
| 138 | } | |
| 139 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
140 | int cx_cmp_ulongint(const void *i1, const void *i2) { |
| 678 | 141 | unsigned long int a = *((const unsigned long int *) i1); |
| 142 | unsigned long int b = *((const unsigned long int *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
143 | return cx_vcmp_ulongint(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
144 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
145 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
146 | int cx_vcmp_ulonglong(unsigned long long a, unsigned long long b) { |
| 601 | 147 | if (a == b) { |
| 148 | return 0; | |
| 149 | } else { | |
| 150 | return a < b ? -1 : 1; | |
| 151 | } | |
| 152 | } | |
| 153 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
154 | int cx_cmp_ulonglong(const void *i1, const void *i2) { |
| 678 | 155 | unsigned long long a = *((const unsigned long long *) i1); |
| 156 | unsigned long long b = *((const unsigned long long *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
157 | return cx_vcmp_ulonglong(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
158 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
159 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
160 | int cx_vcmp_uint16(uint16_t a, uint16_t b) { |
| 601 | 161 | if (a == b) { |
| 162 | return 0; | |
| 163 | } else { | |
| 164 | return a < b ? -1 : 1; | |
| 165 | } | |
| 166 | } | |
| 167 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
168 | int cx_cmp_uint16(const void *i1, const void *i2) { |
| 678 | 169 | uint16_t a = *((const uint16_t *) i1); |
| 170 | uint16_t b = *((const uint16_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
171 | return cx_vcmp_uint16(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
172 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
173 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
174 | int cx_vcmp_uint32(uint32_t a, uint32_t b) { |
| 601 | 175 | if (a == b) { |
| 176 | return 0; | |
| 177 | } else { | |
| 178 | return a < b ? -1 : 1; | |
| 179 | } | |
| 180 | } | |
| 181 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
182 | int cx_cmp_uint32(const void *i1, const void *i2) { |
| 678 | 183 | uint32_t a = *((const uint32_t *) i1); |
| 184 | uint32_t b = *((const uint32_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
185 | return cx_vcmp_uint32(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
186 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
187 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
188 | int cx_vcmp_uint64(uint64_t a, uint64_t b) { |
| 601 | 189 | if (a == b) { |
| 190 | return 0; | |
| 191 | } else { | |
| 192 | return a < b ? -1 : 1; | |
| 193 | } | |
| 194 | } | |
| 195 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
196 | int cx_cmp_uint64(const void *i1, const void *i2) { |
| 678 | 197 | uint64_t a = *((const uint64_t *) i1); |
| 198 | uint64_t b = *((const uint64_t *) i2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
199 | return cx_vcmp_uint64(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
200 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
201 | |
|
1399
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
202 | int cx_vcmp_size(size_t a, size_t b) { |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
203 | if (a == b) { |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
204 | return 0; |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
205 | } else { |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
206 | return a < b ? -1 : 1; |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
207 | } |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
208 | } |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
209 | |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
210 | int cx_cmp_size(const void *i1, const void *i2) { |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
211 | size_t a = *((const size_t *) i1); |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
212 | size_t b = *((const size_t *) i2); |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
213 | return cx_vcmp_size(a, b); |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
214 | } |
|
40c3b850f859
add size_t compare functions
Mike Becker <universe@uap-core.de>
parents:
1062
diff
changeset
|
215 | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
216 | int cx_vcmp_float(float a, float b) { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
217 | if (fabsf(a - b) < 1e-6f) { |
| 601 | 218 | return 0; |
| 219 | } else { | |
| 220 | return a < b ? -1 : 1; | |
| 221 | } | |
| 222 | } | |
| 223 | ||
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
224 | int cx_cmp_float(const void *f1, const void *f2) { |
| 678 | 225 | float a = *((const float *) f1); |
| 226 | float b = *((const float *) f2); | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
227 | return cx_vcmp_float(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
228 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
229 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
230 | int cx_vcmp_double(double a, double b) { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
231 | if (fabs(a - b) < 1e-14) { |
| 601 | 232 | return 0; |
| 233 | } else { | |
| 234 | return a < b ? -1 : 1; | |
| 235 | } | |
| 236 | } | |
| 237 | ||
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
238 | int cx_cmp_double( |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
239 | const void *d1, |
|
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
240 | const void *d2 |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
241 | ) { |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
242 | double a = *((const double *) d1); |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
243 | double b = *((const double *) d2); |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
244 | return cx_vcmp_double(a, b); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
245 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
246 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
247 | int cx_vcmp_intptr(intptr_t p1, intptr_t p2) { |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
248 | if (p1 == p2) { |
| 601 | 249 | return 0; |
| 250 | } else { | |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
251 | return p1 < p2 ? -1 : 1; |
| 601 | 252 | } |
| 253 | } | |
| 254 | ||
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
255 | int cx_cmp_intptr( |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
256 | const void *ptr1, |
|
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
257 | const void *ptr2 |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
258 | ) { |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
259 | intptr_t p1 = *(const intptr_t *) ptr1; |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
260 | intptr_t p2 = *(const intptr_t *) ptr2; |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
261 | return cx_vcmp_intptr(p1, p2); |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
262 | } |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
263 | |
|
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
264 | int cx_vcmp_uintptr(uintptr_t p1, uintptr_t p2) { |
| 601 | 265 | if (p1 == p2) { |
| 266 | return 0; | |
| 267 | } else { | |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
268 | return p1 < p2 ? -1 : 1; |
| 601 | 269 | } |
| 270 | } | |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
271 | |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
272 | int cx_cmp_uintptr( |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
273 | const void *ptr1, |
|
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
274 | const void *ptr2 |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
275 | ) { |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
276 | uintptr_t p1 = *(const uintptr_t *) ptr1; |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
277 | uintptr_t p2 = *(const uintptr_t *) ptr2; |
|
1062
8baed9b38bc6
add cx_vcmp_* family of functions
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
278 | return cx_vcmp_uintptr(p1, p2); |
|
631
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
279 | } |
|
406376e64fd8
tests for compare functions
Mike Becker <universe@uap-core.de>
parents:
601
diff
changeset
|
280 | |
|
762
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
281 | int cx_cmp_ptr( |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
282 | const void *ptr1, |
|
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
762
diff
changeset
|
283 | const void *ptr2 |
|
762
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
284 | ) { |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
285 | uintptr_t p1 = (uintptr_t) ptr1; |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
286 | uintptr_t p2 = (uintptr_t) ptr2; |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
287 | if (p1 == p2) { |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
288 | return 0; |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
289 | } else { |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
290 | return p1 < p2 ? -1 : 1; |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
291 | } |
|
4523f6d42512
add cx_cmp_ptr() - fix #340
Mike Becker <universe@uap-core.de>
parents:
678
diff
changeset
|
292 | } |
|
1618
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
293 | |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
294 | int cx_acmp_memcmp( |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
295 | const void *ptr1, |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
296 | const void *ptr2, |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
297 | void *size |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
298 | ) { |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
299 | size_t n = *(size_t*)size; |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
300 | return memcmp(ptr1, ptr2, n); |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
301 | } |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
302 | |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
303 | int cx_acmp_wrap( |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
304 | const void *ptr1, |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
305 | const void *ptr2, |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
306 | void *w |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
307 | ) { |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
308 | cx_compare_func_wrapper *wrapper = w; |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
309 | return wrapper->cmp(ptr1, ptr2); |
|
ef7cab6eb131
huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents:
1399
diff
changeset
|
310 | } |