*
* int main(void)
* {
- * AVL *avl = avl_new((AvlCompare) strcmp);
+ * AVL *avl = avl_new((total_order_noctx_cb) strcmp);
* AvlIter i;
* struct tally *tally;
* char line[256];
return 1;
if (strcmp(argv[1], "depends") == 0) {
- /* Nothing */
+ printf("ccan/order\n");
return 0;
}
return 1;
}
-AVL *avl_new(AvlCompare compare)
+AVL *avl_new(total_order_noctx_cb compare)
{
AVL *avl = malloc(sizeof(*avl));
#include <stdbool.h>
#include <stddef.h>
+#include <ccan/order/order.h>
+
typedef struct AVL AVL;
typedef struct AvlNode AvlNode;
typedef struct AvlIter AvlIter;
-typedef int (*AvlCompare)(const void *, const void *);
-
-AVL *avl_new(AvlCompare compare);
+AVL *avl_new(total_order_noctx_cb compare);
/* Create a new AVL tree sorted with the given comparison function. */
void avl_free(AVL *avl);
/***************** Internal data structures ******************/
struct AVL {
- AvlCompare compare;
+ total_order_noctx_cb compare;
AvlNode *root;
size_t count;
};
size_t insert_id; /* needed because qsort is not a stable sort */
};
-static int compare_uint32_t(const void *ap, const void *bp)
-{
- uint32_t a = *(const uint32_t *)ap;
- uint32_t b = *(const uint32_t *)bp;
-
- if (a < b)
- return -1;
- if (a > b)
- return 1;
- return 0;
-}
-
static int compare_test_item(const void *ap, const void *bp)
{
const struct test_item *a = *(void**)ap, *b = *(void**)bp;
}
scramble(test_item, count, sizeof(*test_item));
- avl = avl_new(compare_uint32_t);
+ avl = avl_new(order_u32_noctx);
clear_stats();
printf(" Inserting %zu items...\n", count);