Define comparators with BTREE_LESS and BTREE_COMPARE
mainEvery B-tree requires a comparator to order items. The comparator code fragment has access to three variables: a (the first item), b (the second item), and udata (optional user data).
BTREE_LESS: A boolean expression. It should returntrueorfalse. This is generally recommended for numeric comparisons.BTREE_COMPARE: A three-way comparison. It should return-1(ifa < b),0(ifa == b), or1(ifa > b). This is often better suited for strings or complex keys.
#define BTREE_LESS return a < b; /* return true or false */
#define BTREE_COMPARE return a < b ? -1 : a > b; /* return -1, 0, 1 */