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