]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add COMPARE_PREFER_SMALLER / LARGER
authorAlan T. DeKok <aland@freeradius.org>
Sun, 30 Aug 2020 08:56:59 +0000 (04:56 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 30 Aug 2020 08:56:59 +0000 (04:56 -0400)
for ordered comparisons

src/lib/util/heap.h
src/lib/util/rbtree.h

index 1cf0663925d54c64a8fda64b00f5543c8aee7876..90e5a68d983da408347cf38f10010877d8d7bf8d 100644 (file)
@@ -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 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.
index 40370e9c84aaf28a25e232c51bf0a49098f1d4cf..7a2af7a66536e105bacc384c2e3edd01f434395f 100644 (file)
@@ -56,9 +56,15 @@ typedef void (*rb_free_t)(void *data);
 
 #ifndef STABLE_COMPARE
 /*
- *     This comparison returns +1 for a>b, and -1 for a<b
+ *     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 STABLE_COMPARE(_a,_b) (((_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