*/
#define L(_str) { _str, sizeof(_str) - 1 }
-/** Comparison macro for integers
- *
+/** Evaluates to +1 for a > b, and -1 for a < b
+ */
+#define CMP_PREFER_SMALLER(_a,_b) (((_a) > (_b)) - ((_a) < (_b)))
+
+/** Evaluates to -1 for a > b, and +1 for a < b
+ */
+#define CMP_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b)))
+
+/** Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want _an_ ordering.
*/
-#define CMP(_a, _b) (((_a) > (_b)) - ((_a) < (_b)))
+#define CMP(_a, _b) CMP_PREFER_SMALLER(_a, _b)
/** Remove const qualification from a pointer
*
* @param[in] _type The non-const version of the type.
* @param[in] _ptr to de-const.
*/
-#define UNCONST(_type, _ptr) ((_type)((uintptr_t)(_ptr)))
+#define UNCONST(_type, _ptr) ((_type)((uintptr_t)(_ptr)))
/*
* HEX concatenation macros
* priority elements. So if "a" is larger than "b", we
* wish to prefer "a".
*/
- ret = COMPARE_PREFER_LARGER(a->priority, b->priority);
+ ret = CMP_PREFER_LARGER(a->priority, b->priority);
if (ret != 0) return ret;
/*
* packets go in. Since we'll never have two identical
* "recv_time" values, the code should never get here.
*/
- return COMPARE_PREFER_SMALLER(a->recv_time, b->recv_time);
+ return CMP_PREFER_SMALLER(a->recv_time, b->recv_time);
}
/*
fr_io_address_t const *a = talloc_get_type_abort_const(one, fr_io_address_t);
fr_io_address_t const *b = talloc_get_type_abort_const(two, fr_io_address_t);;
- ret = STABLE_COMPARE(a->socket.inet.src_port, b->socket.inet.src_port);
+ ret = CMP(a->socket.inet.src_port, b->socket.inet.src_port);
if (ret != 0) return ret;
- ret = STABLE_COMPARE(a->socket.inet.dst_port, b->socket.inet.dst_port);
+ ret = CMP(a->socket.inet.dst_port, b->socket.inet.dst_port);
if (ret != 0) return ret;
- ret = STABLE_COMPARE(a->socket.inet.ifindex, b->socket.inet.ifindex);
+ ret = CMP(a->socket.inet.ifindex, b->socket.inet.ifindex);
if (ret != 0) return ret;
ret = fr_ipaddr_cmp(&a->socket.inet.src_ipaddr, &b->socket.inet.src_ipaddr);
{
module_method_entry_t const *a = one, *b = two;
- return STABLE_COMPARE(a, b);
+ return CMP(a, b);
}
/** Allocate a new module method set
* because we need to check the lineage.
*/
if (a->flags.is_unknown | a->flags.is_raw | b->flags.is_unknown | b->flags.is_raw) {
- ret = STABLE_COMPARE(a->depth, b->depth);
+ ret = CMP(a->depth, b->depth);
if (ret != 0) return ret;
- ret = STABLE_COMPARE(a->attr, b->attr);
+ ret = CMP(a->attr, b->attr);
if (ret != 0) return ret;
ret = (a->parent == NULL) - (b->parent == NULL);
* Comparing knowns is cheap because the
* DAs are unique.
*/
- return STABLE_COMPARE(a, b);
+ return CMP(a, b);
}
/** @} */
{
fr_event_pid_t const *ev_a = a, *ev_b = b;
- return STABLE_COMPARE(ev_a->pid, ev_b->pid);
+ return CMP(ev_a->pid, ev_b->pid);
}
#endif
typedef int32_t fr_heap_iter_t;
-#ifndef STABLE_COMPARE
-/*
- * The first comparison returns +1 for a>b, and -1 for a<b
- * The second comparison returns -1 for a>b, and +1 for a<b
- *
- * Use STABLE_COMPARE when you don't really care about ordering,
- * you just want _an_ ordering.
- */
-#define COMPARE_PREFER_SMALLER(_a,_b) (((_a) > (_b)) - ((_a) < (_b)))
-#define COMPARE_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b)))
-#define STABLE_COMPARE COMPARE_PREFER_SMALLER
-#endif
-
/*
* Return negative numbers to put 'a' at the top of the heap.
* Return positive numbers to put 'b' at the top of the heap.
typedef int (*fr_rb_cmp_t)(void const *one, void const *two);
typedef void (*fr_rb_free_t)(void *data);
-#ifndef STABLE_COMPARE
-/*
- * The first comparison returns +1 for a>b, and -1 for a<b
- * The second comparison returns -1 for a>b, and +1 for a<b
- *
- * Use STABLE_COMPARE when you don't really care about ordering,
- * you just want _an_ ordering.
- */
-#define COMPARE_PREFER_SMALLER(_a,_b) (((_a) > (_b)) - ((_a) < (_b)))
-#define COMPARE_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b)))
-#define STABLE_COMPARE COMPARE_PREFER_SMALLER
-#endif
-
/** Creates a red black that verifies elements are of a specific talloc type
*
* @param[in] _ctx to tie tree lifetime to.