From 8e84a8ffdaf3c64cc4c4e31c163def44eb9acb12 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 31 Oct 2014 16:41:11 -0700 Subject: [PATCH] I forgot how bad sorted data is in binary trees. Swizzle the bits so deduplicating features isn't so terrible. --- pool.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pool.c b/pool.c index 015d93c..b84c3a7 100644 --- a/pool.c +++ b/pool.c @@ -67,13 +67,22 @@ struct pool_val *pool(struct pool *p, char *s, int type) { return pool1(p, s, type, strcmp); } -static int llcmp(const char *v1, const char *v2) { - long long *ll1 = (long long *) v1; - long long *ll2 = (long long *) v2; +static long long mangle(long long in) { + int i; + long long out = 0; + for (i = 0; i < 64; i++) { + out |= ((in >> i) & 1) << (63 - i); + } + return out; +} - if (*ll1 < *ll2) { +static int llcmp(const char *v1, const char *v2) { + long long ll1 = mangle(*(long long *) v1); + long long ll2 = mangle(*(long long *) v2); + + if (ll1 < ll2) { return -1; - } else if (*ll1 > *ll2) { + } else if (ll1 > ll2) { return 1; } else { return 0;