mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-21 03:55:00 +00:00
Slightly lower average traversal using a hash for comparison
This commit is contained in:
parent
764a8ac17c
commit
93920d06e1
40
pool.cpp
40
pool.cpp
@ -7,31 +7,27 @@
|
|||||||
#include "pool.hpp"
|
#include "pool.hpp"
|
||||||
|
|
||||||
int swizzlecmp(const char *a, const char *b) {
|
int swizzlecmp(const char *a, const char *b) {
|
||||||
ssize_t a1 = strlen(a) - 1;
|
ssize_t alen = strlen(a);
|
||||||
ssize_t b1 = strlen(b) - 1;
|
ssize_t blen = strlen(b);
|
||||||
|
|
||||||
while (a1 >= 0 || b1 >= 0) {
|
if (strcmp(a, b) == 0) {
|
||||||
unsigned char ac = '\0', bc = '\0';
|
return 0;
|
||||||
if (a1 >= 0) {
|
|
||||||
ac = a[a1];
|
|
||||||
}
|
|
||||||
if (b1 >= 0) {
|
|
||||||
bc = b[b1];
|
|
||||||
}
|
|
||||||
|
|
||||||
int aa = ac;
|
|
||||||
int bb = bc;
|
|
||||||
|
|
||||||
int cmp = aa - bb;
|
|
||||||
if (cmp != 0) {
|
|
||||||
return cmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
a1--;
|
|
||||||
b1--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
unsigned int hash1 = 0, hash2 = 0;
|
||||||
|
for (ssize_t i = alen - 1; i >= 0; i--) {
|
||||||
|
hash1 = hash1 * 37 + a[i];
|
||||||
|
}
|
||||||
|
for (ssize_t i = blen - 1; i >= 0; i--) {
|
||||||
|
hash2 = hash2 * 37 + b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
int h1 = hash1, h2 = hash2;
|
||||||
|
if (h1 == h2) {
|
||||||
|
return strcmp(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return h1 - h2;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type) {
|
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user