fix str_hash() for archs enforcing aligned pointers

uses the hashing algorithm from g_str_hash() from glib

fixes #27
changes/57/8857/1
Richard Fuchs 12 years ago
parent c1d7a52552
commit 6379883f7b

@ -2,25 +2,14 @@
#include <assert.h>
#include <stdarg.h>
/* adapted from g_str_hash() from glib */
guint str_hash(gconstpointer ss) {
const str *s = ss;
guint ret = 0;
guint ret = 5381;
str it = *s;
while (it.len >= sizeof(guint)) {
guint *x = (void *) it.s;
ret ^= *x;
it.s += sizeof(guint);
it.len -= sizeof(guint);
}
while (it.len >= sizeof(gushort)) {
gushort *x = (void *) it.s;
ret ^= *x;
it.s += sizeof(gushort);
it.len -= sizeof(gushort);
}
while (it.len > 0) {
ret ^= *it.s;
ret = (ret << 5) + ret + *it.s;
it.s++;
it.len--;
}

Loading…
Cancel
Save