diff options
author | Daniel Berlin <dberlin@dberlin.org> | 2000-06-05 20:49:53 +0000 |
---|---|---|
committer | Daniel Berlin <dberlin@dberlin.org> | 2000-06-05 20:49:53 +0000 |
commit | 357e46e7c9f18a0603aa9a6de440bedb147e57f8 (patch) | |
tree | 7a636a8075ad6888e5c2401e87c859f74c526183 /gdb/bcache.c | |
parent | e6d71bf34e01d840417e4fac1bcedae5fff5b9dc (diff) | |
download | gdb-357e46e7c9f18a0603aa9a6de440bedb147e57f8.zip gdb-357e46e7c9f18a0603aa9a6de440bedb147e57f8.tar.gz gdb-357e46e7c9f18a0603aa9a6de440bedb147e57f8.tar.bz2 |
C++ improvements
Diffstat (limited to 'gdb/bcache.c')
-rw-r--r-- | gdb/bcache.c | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/gdb/bcache.c b/gdb/bcache.c index 96c01ba..fcff55e 100644 --- a/gdb/bcache.c +++ b/gdb/bcache.c @@ -28,42 +28,25 @@ #include "bcache.h" #include "gdb_string.h" /* For memcpy declaration */ - +/* The old hash function was stolen from SDBM. This is what DB 3.0 uses now, + * and is better than the old one. + */ -/* The hash function. */ - unsigned long -hash (void *addr, int length) +hash(void *addr, int length) { - /* If it's a short string, hash on every character. Otherwise, sample - characters from throughout the string. */ - if (length <= 64) - { - char *byte = addr; - unsigned long h = 0; - int i; - - for (i = 0; i < length; i++) - h = h * 65793 ^ (h >> (sizeof (h) * 8 - 6)) ^ byte[i]; - - return h; - } - else - { - char *byte = addr; - int n, i; - unsigned long h = 0; - - for (n = i = 0; n < 64; n++) - { - h = h * 65793 + (h >> (sizeof (h) * 8 - 6)) + byte[i]; - i = h % length; - } - - return h; - } + const unsigned char *k, *e; + unsigned long h; + + k = (const unsigned char *)addr; + e = k+length; + for (h=0; k< e;++k) + { + h *=16777619; + h ^= *k; + } + return (h); } - /* Growing the bcache's hash table. */ |