From e0b290c34fc116c043f51396e2770821ec357522 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 17 Feb 2016 23:21:38 +0100 Subject: [PATCH] Update the g_istr_hash function to use the djb hash --- src/core/misc.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 48a49fa3..74ca4725 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -401,22 +401,15 @@ int g_istr_cmp(gconstpointer v, gconstpointer v2) return g_ascii_strcasecmp((const char *) v, (const char *) v2); } -/* a char* hash function from ASU */ -unsigned int g_istr_hash(gconstpointer v) +guint g_istr_hash(gconstpointer v) { - const char *s = (const char *) v; - unsigned int h = 0, g; + const signed char *p; + guint32 h = 5381; - while (*s != '\0') { - h = (h << 4) + i_toupper(*s); - if ((g = h & 0xf0000000UL)) { - h = h ^ (g >> 24); - h = h ^ g; - } - s++; - } + for (p = v; *p != '\0'; p++) + h = (h << 5) + h + g_ascii_toupper(*p); - return h /* % M */; + return h; } /* Find `mask' from `data', you can use * and ? wildcards. */