From: Alan T. DeKok Date: Sun, 30 Aug 2020 08:56:59 +0000 (-0400) Subject: add COMPARE_PREFER_SMALLER / LARGER X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8b0cbf2006b04426ee698fd99871ab5339e0302;p=thirdparty%2Ffreeradius-server.git add COMPARE_PREFER_SMALLER / LARGER for ordered comparisons --- diff --git a/src/lib/util/heap.h b/src/lib/util/heap.h index 1cf0663925d..90e5a68d983 100644 --- a/src/lib/util/heap.h +++ b/src/lib/util/heap.h @@ -36,6 +36,19 @@ extern "C" { typedef int32_t fr_heap_iter_t; +#ifndef STABLE_COMPARE +/* + * The first comparison returns +1 for a>b, and -1 for ab, and +1 for 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. diff --git a/src/lib/util/rbtree.h b/src/lib/util/rbtree.h index 40370e9c84a..7a2af7a6653 100644 --- a/src/lib/util/rbtree.h +++ b/src/lib/util/rbtree.h @@ -56,9 +56,15 @@ typedef void (*rb_free_t)(void *data); #ifndef STABLE_COMPARE /* - * This comparison returns +1 for a>b, and -1 for ab, and -1 for ab, and +1 for a (_b)) - ((_a) < (_b))) +#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