ucx/cx/compare.h

changeset 11
0aa8cbd7912e
parent 0
1a157da63d7c
child 16
04c9f8d8f03b
equal deleted inserted replaced
10:80f9d007cb52 11:0aa8cbd7912e
40 40
41 #ifdef __cplusplus 41 #ifdef __cplusplus
42 extern "C" { 42 extern "C" {
43 #endif 43 #endif
44 44
45 #ifndef CX_COMPARE_FUNC_DEFINED 45 /**
46 #define CX_COMPARE_FUNC_DEFINED 46 * A comparator function comparing two arbitrary values.
47 /** 47 *
48 * A comparator function comparing two collection elements. 48 * All functions from compare.h with the cx_cmp prefix are
49 */ 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.
56 */
57 cx_attr_nonnull
58 cx_attr_nodiscard
50 typedef int(*cx_compare_func)( 59 typedef int(*cx_compare_func)(
51 void const *left, 60 const void *left,
52 void const *right 61 const void *right
53 ); 62 );
54 #endif // CX_COMPARE_FUNC_DEFINED
55 63
56 /** 64 /**
57 * Compares two integers of type int. 65 * Compares two integers of type int.
58 * 66 *
59 * @param i1 pointer to integer one 67 * @param i1 pointer to integer one
60 * @param i2 pointer to integer two 68 * @param i2 pointer to integer two
61 * @return -1, if *i1 is less than *i2, 0 if both are equal, 69 * @return -1, if *i1 is less than *i2, 0 if both are equal,
62 * 1 if *i1 is greater than *i2 70 * 1 if *i1 is greater than *i2
63 */ 71 */
64 int cx_cmp_int(void const *i1, void const *i2); 72 cx_attr_nonnull
73 cx_attr_nodiscard
74 int cx_cmp_int(const void *i1, const void *i2);
75
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);
65 86
66 /** 87 /**
67 * Compares two integers of type long int. 88 * Compares two integers of type long int.
68 * 89 *
69 * @param i1 pointer to long integer one 90 * @param i1 pointer to long integer one
70 * @param i2 pointer to long integer two 91 * @param i2 pointer to long integer two
71 * @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,
72 * 1 if *i1 is greater than *i2 93 * 1 if *i1 is greater than *i2
73 */ 94 */
74 int cx_cmp_longint(void const *i1, void const *i2); 95 cx_attr_nonnull
96 cx_attr_nodiscard
97 int cx_cmp_longint(const void *i1, const void *i2);
98
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);
75 109
76 /** 110 /**
77 * Compares two integers of type long long. 111 * Compares two integers of type long long.
78 * 112 *
79 * @param i1 pointer to long long one 113 * @param i1 pointer to long long one
80 * @param i2 pointer to long long two 114 * @param i2 pointer to long long two
81 * @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,
82 * 1 if *i1 is greater than *i2 116 * 1 if *i1 is greater than *i2
83 */ 117 */
84 int cx_cmp_longlong(void const *i1, void const *i2); 118 cx_attr_nonnull
119 cx_attr_nodiscard
120 int cx_cmp_longlong(const void *i1, const void *i2);
121
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);
85 132
86 /** 133 /**
87 * Compares two integers of type int16_t. 134 * Compares two integers of type int16_t.
88 * 135 *
89 * @param i1 pointer to int16_t one 136 * @param i1 pointer to int16_t one
90 * @param i2 pointer to int16_t two 137 * @param i2 pointer to int16_t two
91 * @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,
92 * 1 if *i1 is greater than *i2 139 * 1 if *i1 is greater than *i2
93 */ 140 */
94 int cx_cmp_int16(void const *i1, void const *i2); 141 cx_attr_nonnull
142 cx_attr_nodiscard
143 int cx_cmp_int16(const void *i1, const void *i2);
144
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);
95 155
96 /** 156 /**
97 * Compares two integers of type int32_t. 157 * Compares two integers of type int32_t.
98 * 158 *
99 * @param i1 pointer to int32_t one 159 * @param i1 pointer to int32_t one
100 * @param i2 pointer to int32_t two 160 * @param i2 pointer to int32_t two
101 * @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,
102 * 1 if *i1 is greater than *i2 162 * 1 if *i1 is greater than *i2
103 */ 163 */
104 int cx_cmp_int32(void const *i1, void const *i2); 164 cx_attr_nonnull
165 cx_attr_nodiscard
166 int cx_cmp_int32(const void *i1, const void *i2);
167
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);
105 178
106 /** 179 /**
107 * Compares two integers of type int64_t. 180 * Compares two integers of type int64_t.
108 * 181 *
109 * @param i1 pointer to int64_t one 182 * @param i1 pointer to int64_t one
110 * @param i2 pointer to int64_t two 183 * @param i2 pointer to int64_t two
111 * @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,
112 * 1 if *i1 is greater than *i2 185 * 1 if *i1 is greater than *i2
113 */ 186 */
114 int cx_cmp_int64(void const *i1, void const *i2); 187 cx_attr_nonnull
188 cx_attr_nodiscard
189 int cx_cmp_int64(const void *i1, const void *i2);
190
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);
115 201
116 /** 202 /**
117 * Compares two integers of type unsigned int. 203 * Compares two integers of type unsigned int.
118 * 204 *
119 * @param i1 pointer to unsigned integer one 205 * @param i1 pointer to unsigned integer one
120 * @param i2 pointer to unsigned integer two 206 * @param i2 pointer to unsigned integer two
121 * @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,
122 * 1 if *i1 is greater than *i2 208 * 1 if *i1 is greater than *i2
123 */ 209 */
124 int cx_cmp_uint(void const *i1, void const *i2); 210 cx_attr_nonnull
211 cx_attr_nodiscard
212 int cx_cmp_uint(const void *i1, const void *i2);
213
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);
125 224
126 /** 225 /**
127 * Compares two integers of type unsigned long int. 226 * Compares two integers of type unsigned long int.
128 * 227 *
129 * @param i1 pointer to unsigned long integer one 228 * @param i1 pointer to unsigned long integer one
130 * @param i2 pointer to unsigned long integer two 229 * @param i2 pointer to unsigned long integer two
131 * @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,
132 * 1 if *i1 is greater than *i2 231 * 1 if *i1 is greater than *i2
133 */ 232 */
134 int cx_cmp_ulongint(void const *i1, void const *i2); 233 cx_attr_nonnull
234 cx_attr_nodiscard
235 int cx_cmp_ulongint(const void *i1, const void *i2);
236
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);
135 247
136 /** 248 /**
137 * Compares two integers of type unsigned long long. 249 * Compares two integers of type unsigned long long.
138 * 250 *
139 * @param i1 pointer to unsigned long long one 251 * @param i1 pointer to unsigned long long one
140 * @param i2 pointer to unsigned long long two 252 * @param i2 pointer to unsigned long long two
141 * @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,
142 * 1 if *i1 is greater than *i2 254 * 1 if *i1 is greater than *i2
143 */ 255 */
144 int cx_cmp_ulonglong(void const *i1, void const *i2); 256 cx_attr_nonnull
257 cx_attr_nodiscard
258 int cx_cmp_ulonglong(const void *i1, const void *i2);
259
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);
145 270
146 /** 271 /**
147 * Compares two integers of type uint16_t. 272 * Compares two integers of type uint16_t.
148 * 273 *
149 * @param i1 pointer to uint16_t one 274 * @param i1 pointer to uint16_t one
150 * @param i2 pointer to uint16_t two 275 * @param i2 pointer to uint16_t two
151 * @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,
152 * 1 if *i1 is greater than *i2 277 * 1 if *i1 is greater than *i2
153 */ 278 */
154 int cx_cmp_uint16(void const *i1, void const *i2); 279 cx_attr_nonnull
280 cx_attr_nodiscard
281 int cx_cmp_uint16(const void *i1, const void *i2);
282
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);
155 293
156 /** 294 /**
157 * Compares two integers of type uint32_t. 295 * Compares two integers of type uint32_t.
158 * 296 *
159 * @param i1 pointer to uint32_t one 297 * @param i1 pointer to uint32_t one
160 * @param i2 pointer to uint32_t two 298 * @param i2 pointer to uint32_t two
161 * @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,
162 * 1 if *i1 is greater than *i2 300 * 1 if *i1 is greater than *i2
163 */ 301 */
164 int cx_cmp_uint32(void const *i1, void const *i2); 302 cx_attr_nonnull
303 cx_attr_nodiscard
304 int cx_cmp_uint32(const void *i1, const void *i2);
305
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);
165 316
166 /** 317 /**
167 * Compares two integers of type uint64_t. 318 * Compares two integers of type uint64_t.
168 * 319 *
169 * @param i1 pointer to uint64_t one 320 * @param i1 pointer to uint64_t one
170 * @param i2 pointer to uint64_t two 321 * @param i2 pointer to uint64_t two
171 * @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,
172 * 1 if *i1 is greater than *i2 323 * 1 if *i1 is greater than *i2
173 */ 324 */
174 int cx_cmp_uint64(void const *i1, void const *i2); 325 cx_attr_nonnull
326 cx_attr_nodiscard
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);
175 339
176 /** 340 /**
177 * Compares two real numbers of type float with precision 1e-6f. 341 * Compares two real numbers of type float with precision 1e-6f.
178 * 342 *
179 * @param f1 pointer to float one 343 * @param f1 pointer to float one
180 * @param f2 pointer to float two 344 * @param f2 pointer to float two
181 * @return -1, if *f1 is less than *f2, 0 if both are equal, 345 * @return -1, if *f1 is less than *f2, 0 if both are equal,
182 * 1 if *f1 is greater than *f2 346 * 1 if *f1 is greater than *f2
183 */ 347 */
184 348 cx_attr_nonnull
185 int cx_cmp_float(void const *f1, void const *f2); 349 cx_attr_nodiscard
350 int cx_cmp_float(const void *f1, const void *f2);
351
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);
186 362
187 /** 363 /**
188 * Compares two real numbers of type double with precision 1e-14. 364 * Compares two real numbers of type double with precision 1e-14.
189 * 365 *
190 * @param d1 pointer to double one 366 * @param d1 pointer to double one
191 * @param d2 pointer to double two 367 * @param d2 pointer to double two
192 * @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,
193 * 1 if *d1 is greater than *d2 369 * 1 if *d1 is greater than *d2
194 */ 370 */
195 int cx_cmp_double( 371 cx_attr_nonnull
196 void const *d1, 372 cx_attr_nodiscard
197 void const *d2 373 int cx_cmp_double(const void *d1, const void *d2);
198 ); 374
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);
199 385
200 /** 386 /**
201 * Compares the integer representation of two pointers. 387 * Compares the integer representation of two pointers.
202 * 388 *
203 * @param ptr1 pointer to pointer one (intptr_t const*) 389 * @param ptr1 pointer to pointer one (const intptr_t*)
204 * @param ptr2 pointer to pointer two (intptr_t const*) 390 * @param ptr2 pointer to pointer two (const intptr_t*)
205 * @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,
206 * 1 if *ptr1 is greater than *ptr2 392 * 1 if *ptr1 is greater than *ptr2
207 */ 393 */
208 int cx_cmp_intptr( 394 cx_attr_nonnull
209 void const *ptr1, 395 cx_attr_nodiscard
210 void const *ptr2 396 int cx_cmp_intptr(const void *ptr1, const void *ptr2);
211 ); 397
212 398 /**
213 /** 399 * Compares the integer representation of two pointers.
214 * Compares the unsigned integer representation of two pointers.
215 *
216 * @param ptr1 pointer to pointer one (uintptr_t const*)
217 * @param ptr2 pointer to pointer two (uintptr_t const*)
218 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
219 * 1 if *ptr1 is greater than *ptr2
220 */
221 int cx_cmp_uintptr(
222 void const *ptr1,
223 void const *ptr2
224 );
225
226 /**
227 * Compares the pointers specified in the arguments without de-referencing.
228 * 400 *
229 * @param ptr1 pointer one 401 * @param ptr1 pointer one
230 * @param ptr2 pointer two 402 * @param ptr2 pointer two
231 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 403 * @return -1 if ptr1 is less than ptr2, 0 if both are equal,
232 * 1 if ptr1 is greater than ptr2 404 * 1 if ptr1 is greater than ptr2
233 */ 405 */
234 int cx_cmp_ptr( 406 cx_attr_nodiscard
235 void const *ptr1, 407 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2);
236 void const *ptr2 408
237 ); 409 /**
410 * Compares the unsigned integer representation of two pointers.
411 *
412 * @param ptr1 pointer to pointer one (const uintptr_t*)
413 * @param ptr2 pointer to pointer two (const uintptr_t*)
414 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
415 * 1 if *ptr1 is greater than *ptr2
416 */
417 cx_attr_nonnull
418 cx_attr_nodiscard
419 int cx_cmp_uintptr(const void *ptr1, const void *ptr2);
420
421 /**
422 * Compares the unsigned integer representation of two pointers.
423 *
424 * @param ptr1 pointer one
425 * @param ptr2 pointer two
426 * @return -1 if ptr1 is less than ptr2, 0 if both are equal,
427 * 1 if ptr1 is greater than ptr2
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 */
440 cx_attr_nonnull
441 cx_attr_nodiscard
442 int cx_cmp_ptr(const void *ptr1, const void *ptr2);
238 443
239 #ifdef __cplusplus 444 #ifdef __cplusplus
240 } // extern "C" 445 } // extern "C"
241 #endif 446 #endif
242 447

mercurial