1 /* CC0 license (public domain) - see LICENSE file for details */
3 #include <ccan/order/order.h>
5 #define SCALAR_ORDER(_oname, _type) \
6 int _order_##_oname(const void *a, \
10 ptrdiff_t offset = ptr2int(ctx); \
11 const _type *aa = (const _type *)((char *)a + offset); \
12 const _type *bb = (const _type *)((char *)b + offset); \
16 } else if (*aa > *bb) { \
23 int order_##_oname(const _type *a, \
27 return _order_##_oname(a, b, int2ptr(0)); \
29 int _order_##_oname##_reverse(const void *a, \
33 return -_order_##_oname(a, b, ctx); \
35 int order_##_oname##_reverse(const _type *a, \
39 return _order_##_oname##_reverse(a, b, int2ptr(0)); \
41 int order_##_oname##_noctx(const void *a, \
44 return _order_##_oname(a, b, int2ptr(0)); \
46 int order_##_oname##_reverse_noctx(const void *a, \
49 return _order_##_oname##_reverse(a, b, int2ptr(0)); \
52 SCALAR_ORDER(s8, int8_t)
53 SCALAR_ORDER(s16, int16_t)
54 SCALAR_ORDER(s32, int32_t)
55 SCALAR_ORDER(s64, int64_t)
57 SCALAR_ORDER(u8, uint8_t)
58 SCALAR_ORDER(u16, uint16_t)
59 SCALAR_ORDER(u32, uint32_t)
60 SCALAR_ORDER(u64, uint64_t)
62 SCALAR_ORDER(int, int)
63 SCALAR_ORDER(uint, unsigned int)
64 SCALAR_ORDER(long, long)
65 SCALAR_ORDER(ulong, unsigned long)
66 SCALAR_ORDER(size, size_t)
67 SCALAR_ORDER(ptrdiff, ptrdiff_t)
69 SCALAR_ORDER(float, float)
70 SCALAR_ORDER(double, double)