| 41 #ifdef __cplusplus |
41 #ifdef __cplusplus |
| 42 extern "C" { |
42 extern "C" { |
| 43 #endif |
43 #endif |
| 44 |
44 |
| 45 /** |
45 /** |
| 46 * A comparator function comparing two collection elements. |
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 |
| |
50 * compare function for collections, or other implementations |
| |
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. |
| 47 */ |
56 */ |
| 48 cx_attr_nonnull |
57 cx_attr_nonnull |
| 49 cx_attr_nodiscard |
58 cx_attr_nodiscard |
| 50 typedef int(*cx_compare_func)( |
59 typedef int(*cx_compare_func)( |
| 51 const void *left, |
60 const void *left, |
| 63 cx_attr_nonnull |
72 cx_attr_nonnull |
| 64 cx_attr_nodiscard |
73 cx_attr_nodiscard |
| 65 int cx_cmp_int(const void *i1, const void *i2); |
74 int cx_cmp_int(const void *i1, const void *i2); |
| 66 |
75 |
| 67 /** |
76 /** |
| |
77 * Compares two ints. |
| |
78 * |
| |
79 * @param i1 integer one |
| |
80 * @param i2 integer two |
| |
81 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
82 * 1 if i1 is greater than i2 |
| |
83 */ |
| |
84 cx_attr_nodiscard |
| |
85 int cx_vcmp_int(int i1, int i2); |
| |
86 |
| |
87 /** |
| 68 * Compares two integers of type long int. |
88 * Compares two integers of type long int. |
| 69 * |
89 * |
| 70 * @param i1 pointer to long integer one |
90 * @param i1 pointer to long integer one |
| 71 * @param i2 pointer to long integer two |
91 * @param i2 pointer to long integer two |
| 72 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
92 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 75 cx_attr_nonnull |
95 cx_attr_nonnull |
| 76 cx_attr_nodiscard |
96 cx_attr_nodiscard |
| 77 int cx_cmp_longint(const void *i1, const void *i2); |
97 int cx_cmp_longint(const void *i1, const void *i2); |
| 78 |
98 |
| 79 /** |
99 /** |
| |
100 * Compares two long ints. |
| |
101 * |
| |
102 * @param i1 long integer one |
| |
103 * @param i2 long integer two |
| |
104 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
105 * 1 if i1 is greater than i2 |
| |
106 */ |
| |
107 cx_attr_nodiscard |
| |
108 int cx_vcmp_longint(long int i1, long int i2); |
| |
109 |
| |
110 /** |
| 80 * Compares two integers of type long long. |
111 * Compares two integers of type long long. |
| 81 * |
112 * |
| 82 * @param i1 pointer to long long one |
113 * @param i1 pointer to long long one |
| 83 * @param i2 pointer to long long two |
114 * @param i2 pointer to long long two |
| 84 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
115 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 87 cx_attr_nonnull |
118 cx_attr_nonnull |
| 88 cx_attr_nodiscard |
119 cx_attr_nodiscard |
| 89 int cx_cmp_longlong(const void *i1, const void *i2); |
120 int cx_cmp_longlong(const void *i1, const void *i2); |
| 90 |
121 |
| 91 /** |
122 /** |
| |
123 * Compares twolong long ints. |
| |
124 * |
| |
125 * @param i1 long long int one |
| |
126 * @param i2 long long int two |
| |
127 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
128 * 1 if i1 is greater than i2 |
| |
129 */ |
| |
130 cx_attr_nodiscard |
| |
131 int cx_vcmp_longlong(long long int i1, long long int i2); |
| |
132 |
| |
133 /** |
| 92 * Compares two integers of type int16_t. |
134 * Compares two integers of type int16_t. |
| 93 * |
135 * |
| 94 * @param i1 pointer to int16_t one |
136 * @param i1 pointer to int16_t one |
| 95 * @param i2 pointer to int16_t two |
137 * @param i2 pointer to int16_t two |
| 96 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
138 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 99 cx_attr_nonnull |
141 cx_attr_nonnull |
| 100 cx_attr_nodiscard |
142 cx_attr_nodiscard |
| 101 int cx_cmp_int16(const void *i1, const void *i2); |
143 int cx_cmp_int16(const void *i1, const void *i2); |
| 102 |
144 |
| 103 /** |
145 /** |
| |
146 * Compares two integers of type int16_t. |
| |
147 * |
| |
148 * @param i1 int16_t one |
| |
149 * @param i2 int16_t two |
| |
150 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
151 * 1 if i1 is greater than i2 |
| |
152 */ |
| |
153 cx_attr_nodiscard |
| |
154 int cx_vcmp_int16(int16_t i1, int16_t i2); |
| |
155 |
| |
156 /** |
| 104 * Compares two integers of type int32_t. |
157 * Compares two integers of type int32_t. |
| 105 * |
158 * |
| 106 * @param i1 pointer to int32_t one |
159 * @param i1 pointer to int32_t one |
| 107 * @param i2 pointer to int32_t two |
160 * @param i2 pointer to int32_t two |
| 108 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
161 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 111 cx_attr_nonnull |
164 cx_attr_nonnull |
| 112 cx_attr_nodiscard |
165 cx_attr_nodiscard |
| 113 int cx_cmp_int32(const void *i1, const void *i2); |
166 int cx_cmp_int32(const void *i1, const void *i2); |
| 114 |
167 |
| 115 /** |
168 /** |
| |
169 * Compares two integers of type int32_t. |
| |
170 * |
| |
171 * @param i1 int32_t one |
| |
172 * @param i2 int32_t two |
| |
173 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
174 * 1 if i1 is greater than i2 |
| |
175 */ |
| |
176 cx_attr_nodiscard |
| |
177 int cx_vcmp_int32(int32_t i1, int32_t i2); |
| |
178 |
| |
179 /** |
| 116 * Compares two integers of type int64_t. |
180 * Compares two integers of type int64_t. |
| 117 * |
181 * |
| 118 * @param i1 pointer to int64_t one |
182 * @param i1 pointer to int64_t one |
| 119 * @param i2 pointer to int64_t two |
183 * @param i2 pointer to int64_t two |
| 120 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
184 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 123 cx_attr_nonnull |
187 cx_attr_nonnull |
| 124 cx_attr_nodiscard |
188 cx_attr_nodiscard |
| 125 int cx_cmp_int64(const void *i1, const void *i2); |
189 int cx_cmp_int64(const void *i1, const void *i2); |
| 126 |
190 |
| 127 /** |
191 /** |
| |
192 * Compares two integers of type int64_t. |
| |
193 * |
| |
194 * @param i1 int64_t one |
| |
195 * @param i2 int64_t two |
| |
196 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
197 * 1 if i1 is greater than i2 |
| |
198 */ |
| |
199 cx_attr_nodiscard |
| |
200 int cx_vcmp_int64(int64_t i1, int64_t i2); |
| |
201 |
| |
202 /** |
| 128 * Compares two integers of type unsigned int. |
203 * Compares two integers of type unsigned int. |
| 129 * |
204 * |
| 130 * @param i1 pointer to unsigned integer one |
205 * @param i1 pointer to unsigned integer one |
| 131 * @param i2 pointer to unsigned integer two |
206 * @param i2 pointer to unsigned integer two |
| 132 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
207 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 135 cx_attr_nonnull |
210 cx_attr_nonnull |
| 136 cx_attr_nodiscard |
211 cx_attr_nodiscard |
| 137 int cx_cmp_uint(const void *i1, const void *i2); |
212 int cx_cmp_uint(const void *i1, const void *i2); |
| 138 |
213 |
| 139 /** |
214 /** |
| |
215 * Compares two unsigned ints. |
| |
216 * |
| |
217 * @param i1 unsigned integer one |
| |
218 * @param i2 unsigned integer two |
| |
219 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
220 * 1 if i1 is greater than i2 |
| |
221 */ |
| |
222 cx_attr_nodiscard |
| |
223 int cx_vcmp_uint(unsigned int i1, unsigned int i2); |
| |
224 |
| |
225 /** |
| 140 * Compares two integers of type unsigned long int. |
226 * Compares two integers of type unsigned long int. |
| 141 * |
227 * |
| 142 * @param i1 pointer to unsigned long integer one |
228 * @param i1 pointer to unsigned long integer one |
| 143 * @param i2 pointer to unsigned long integer two |
229 * @param i2 pointer to unsigned long integer two |
| 144 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
230 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 147 cx_attr_nonnull |
233 cx_attr_nonnull |
| 148 cx_attr_nodiscard |
234 cx_attr_nodiscard |
| 149 int cx_cmp_ulongint(const void *i1, const void *i2); |
235 int cx_cmp_ulongint(const void *i1, const void *i2); |
| 150 |
236 |
| 151 /** |
237 /** |
| |
238 * Compares two unsigned long ints. |
| |
239 * |
| |
240 * @param i1 unsigned long integer one |
| |
241 * @param i2 unsigned long integer two |
| |
242 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
243 * 1 if i1 is greater than i2 |
| |
244 */ |
| |
245 cx_attr_nodiscard |
| |
246 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2); |
| |
247 |
| |
248 /** |
| 152 * Compares two integers of type unsigned long long. |
249 * Compares two integers of type unsigned long long. |
| 153 * |
250 * |
| 154 * @param i1 pointer to unsigned long long one |
251 * @param i1 pointer to unsigned long long one |
| 155 * @param i2 pointer to unsigned long long two |
252 * @param i2 pointer to unsigned long long two |
| 156 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
253 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 159 cx_attr_nonnull |
256 cx_attr_nonnull |
| 160 cx_attr_nodiscard |
257 cx_attr_nodiscard |
| 161 int cx_cmp_ulonglong(const void *i1, const void *i2); |
258 int cx_cmp_ulonglong(const void *i1, const void *i2); |
| 162 |
259 |
| 163 /** |
260 /** |
| |
261 * Compares two unsigned long long ints. |
| |
262 * |
| |
263 * @param i1 unsigned long long one |
| |
264 * @param i2 unsigned long long two |
| |
265 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
266 * 1 if i1 is greater than i2 |
| |
267 */ |
| |
268 cx_attr_nodiscard |
| |
269 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2); |
| |
270 |
| |
271 /** |
| 164 * Compares two integers of type uint16_t. |
272 * Compares two integers of type uint16_t. |
| 165 * |
273 * |
| 166 * @param i1 pointer to uint16_t one |
274 * @param i1 pointer to uint16_t one |
| 167 * @param i2 pointer to uint16_t two |
275 * @param i2 pointer to uint16_t two |
| 168 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
276 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 171 cx_attr_nonnull |
279 cx_attr_nonnull |
| 172 cx_attr_nodiscard |
280 cx_attr_nodiscard |
| 173 int cx_cmp_uint16(const void *i1, const void *i2); |
281 int cx_cmp_uint16(const void *i1, const void *i2); |
| 174 |
282 |
| 175 /** |
283 /** |
| |
284 * Compares two integers of type uint16_t. |
| |
285 * |
| |
286 * @param i1 uint16_t one |
| |
287 * @param i2 uint16_t two |
| |
288 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
289 * 1 if i1 is greater than i2 |
| |
290 */ |
| |
291 cx_attr_nodiscard |
| |
292 int cx_vcmp_uint16(uint16_t i1, uint16_t i2); |
| |
293 |
| |
294 /** |
| 176 * Compares two integers of type uint32_t. |
295 * Compares two integers of type uint32_t. |
| 177 * |
296 * |
| 178 * @param i1 pointer to uint32_t one |
297 * @param i1 pointer to uint32_t one |
| 179 * @param i2 pointer to uint32_t two |
298 * @param i2 pointer to uint32_t two |
| 180 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
299 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 183 cx_attr_nonnull |
302 cx_attr_nonnull |
| 184 cx_attr_nodiscard |
303 cx_attr_nodiscard |
| 185 int cx_cmp_uint32(const void *i1, const void *i2); |
304 int cx_cmp_uint32(const void *i1, const void *i2); |
| 186 |
305 |
| 187 /** |
306 /** |
| |
307 * Compares two integers of type uint32_t. |
| |
308 * |
| |
309 * @param i1 uint32_t one |
| |
310 * @param i2 uint32_t two |
| |
311 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
312 * 1 if i1 is greater than i2 |
| |
313 */ |
| |
314 cx_attr_nodiscard |
| |
315 int cx_vcmp_uint32(uint32_t i1, uint32_t i2); |
| |
316 |
| |
317 /** |
| 188 * Compares two integers of type uint64_t. |
318 * Compares two integers of type uint64_t. |
| 189 * |
319 * |
| 190 * @param i1 pointer to uint64_t one |
320 * @param i1 pointer to uint64_t one |
| 191 * @param i2 pointer to uint64_t two |
321 * @param i2 pointer to uint64_t two |
| 192 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
322 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 193 * 1 if *i1 is greater than *i2 |
323 * 1 if *i1 is greater than *i2 |
| 194 */ |
324 */ |
| 195 cx_attr_nonnull |
325 cx_attr_nonnull |
| 196 cx_attr_nodiscard |
326 cx_attr_nodiscard |
| 197 int cx_cmp_uint64(const void *i1, const void *i2); |
327 int cx_cmp_uint64(const void *i1, const void *i2); |
| |
328 |
| |
329 /** |
| |
330 * Compares two integers of type uint64_t. |
| |
331 * |
| |
332 * @param i1 uint64_t one |
| |
333 * @param i2 uint64_t two |
| |
334 * @return -1, if i1 is less than i2, 0 if both are equal, |
| |
335 * 1 if i1 is greater than i2 |
| |
336 */ |
| |
337 cx_attr_nodiscard |
| |
338 int cx_vcmp_uint64(uint64_t i1, uint64_t i2); |
| 198 |
339 |
| 199 /** |
340 /** |
| 200 * Compares two real numbers of type float with precision 1e-6f. |
341 * Compares two real numbers of type float with precision 1e-6f. |
| 201 * |
342 * |
| 202 * @param f1 pointer to float one |
343 * @param f1 pointer to float one |
| 207 cx_attr_nonnull |
348 cx_attr_nonnull |
| 208 cx_attr_nodiscard |
349 cx_attr_nodiscard |
| 209 int cx_cmp_float(const void *f1, const void *f2); |
350 int cx_cmp_float(const void *f1, const void *f2); |
| 210 |
351 |
| 211 /** |
352 /** |
| |
353 * Compares two real numbers of type float with precision 1e-6f. |
| |
354 * |
| |
355 * @param f1 float one |
| |
356 * @param f2 float two |
| |
357 * @return -1, if f1 is less than f2, 0 if both are equal, |
| |
358 * 1 if f1 is greater than f2 |
| |
359 */ |
| |
360 cx_attr_nodiscard |
| |
361 int cx_vcmp_float(float f1, float f2); |
| |
362 |
| |
363 /** |
| 212 * Compares two real numbers of type double with precision 1e-14. |
364 * Compares two real numbers of type double with precision 1e-14. |
| 213 * |
365 * |
| 214 * @param d1 pointer to double one |
366 * @param d1 pointer to double one |
| 215 * @param d2 pointer to double two |
367 * @param d2 pointer to double two |
| 216 * @return -1, if *d1 is less than *d2, 0 if both are equal, |
368 * @return -1, if *d1 is less than *d2, 0 if both are equal, |
| 219 cx_attr_nonnull |
371 cx_attr_nonnull |
| 220 cx_attr_nodiscard |
372 cx_attr_nodiscard |
| 221 int cx_cmp_double(const void *d1, const void *d2); |
373 int cx_cmp_double(const void *d1, const void *d2); |
| 222 |
374 |
| 223 /** |
375 /** |
| |
376 * Convenience function |
| |
377 * |
| |
378 * @param d1 double one |
| |
379 * @param d2 double two |
| |
380 * @return -1, if d1 is less than d2, 0 if both are equal, |
| |
381 * 1 if d1 is greater than d2 |
| |
382 */ |
| |
383 cx_attr_nodiscard |
| |
384 int cx_vcmp_double(double d1, double d2); |
| |
385 |
| |
386 /** |
| 224 * Compares the integer representation of two pointers. |
387 * Compares the integer representation of two pointers. |
| 225 * |
388 * |
| 226 * @param ptr1 pointer to pointer one (const intptr_t*) |
389 * @param ptr1 pointer to pointer one (const intptr_t*) |
| 227 * @param ptr2 pointer to pointer two (const intptr_t*) |
390 * @param ptr2 pointer to pointer two (const intptr_t*) |
| 228 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
391 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
| 231 cx_attr_nonnull |
394 cx_attr_nonnull |
| 232 cx_attr_nodiscard |
395 cx_attr_nodiscard |
| 233 int cx_cmp_intptr(const void *ptr1, const void *ptr2); |
396 int cx_cmp_intptr(const void *ptr1, const void *ptr2); |
| 234 |
397 |
| 235 /** |
398 /** |
| |
399 * Compares the integer representation of two pointers. |
| |
400 * |
| |
401 * @param ptr1 pointer one |
| |
402 * @param ptr2 pointer two |
| |
403 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
| |
404 * 1 if ptr1 is greater than ptr2 |
| |
405 */ |
| |
406 cx_attr_nodiscard |
| |
407 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2); |
| |
408 |
| |
409 /** |
| 236 * Compares the unsigned integer representation of two pointers. |
410 * Compares the unsigned integer representation of two pointers. |
| 237 * |
411 * |
| 238 * @param ptr1 pointer to pointer one (const uintptr_t*) |
412 * @param ptr1 pointer to pointer one (const uintptr_t*) |
| 239 * @param ptr2 pointer to pointer two (const uintptr_t*) |
413 * @param ptr2 pointer to pointer two (const uintptr_t*) |
| 240 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
414 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
| 243 cx_attr_nonnull |
417 cx_attr_nonnull |
| 244 cx_attr_nodiscard |
418 cx_attr_nodiscard |
| 245 int cx_cmp_uintptr(const void *ptr1, const void *ptr2); |
419 int cx_cmp_uintptr(const void *ptr1, const void *ptr2); |
| 246 |
420 |
| 247 /** |
421 /** |
| 248 * Compares the pointers specified in the arguments without de-referencing. |
422 * Compares the unsigned integer representation of two pointers. |
| 249 * |
423 * |
| 250 * @param ptr1 pointer one |
424 * @param ptr1 pointer one |
| 251 * @param ptr2 pointer two |
425 * @param ptr2 pointer two |
| 252 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
426 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
| 253 * 1 if ptr1 is greater than ptr2 |
427 * 1 if ptr1 is greater than ptr2 |
| 254 */ |
428 */ |
| |
429 cx_attr_nodiscard |
| |
430 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2); |
| |
431 |
| |
432 /** |
| |
433 * Compares the pointers specified in the arguments without de-referencing. |
| |
434 * |
| |
435 * @param ptr1 pointer one |
| |
436 * @param ptr2 pointer two |
| |
437 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
| |
438 * 1 if ptr1 is greater than ptr2 |
| |
439 */ |
| 255 cx_attr_nonnull |
440 cx_attr_nonnull |
| 256 cx_attr_nodiscard |
441 cx_attr_nodiscard |
| 257 int cx_cmp_ptr(const void *ptr1, const void *ptr2); |
442 int cx_cmp_ptr(const void *ptr1, const void *ptr2); |
| 258 |
443 |
| 259 #ifdef __cplusplus |
444 #ifdef __cplusplus |