I forgot how bad sorted data is in binary trees.

Swizzle the bits so deduplicating features isn't so terrible.
This commit is contained in:
Eric Fischer 2014-10-31 16:41:11 -07:00
parent ea7216641b
commit 8e84a8ffda

19
pool.c
View File

@ -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;