X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fhash.c;h=41b9570e0b853c474b338ebe0bd8b731e4852ab9;hb=09b372c3074a7cc339a61b2297583f2b9edefe86;hp=71e3b44670cc83969a6b46ad1184026f5e46c9d1;hpb=3e447015251ce6dcde843cbed10d9033d5538622;p=chise%2Fxemacs-chise.git.1 diff --git a/src/hash.c b/src/hash.c index 71e3b44..41b9570 100644 --- a/src/hash.c +++ b/src/hash.c @@ -52,6 +52,25 @@ memory_hash (const void *xv, size_t size) return h; } +unsigned long +string_hash (const char *xv) +{ + unsigned int h = 0; + unsigned const char *x = (unsigned const char *) xv; + + if (!x) return 0; + + while (*x) + { + unsigned int g; + h = (h << 4) + *x++; + if ((g = h & 0xf0000000) != 0) + h = (h ^ (g >> 24)) ^ g; + } + + return h; +} + /* Return a suitable size for a hash table, with at least SIZE slots. */ static size_t hash_table_size (size_t requested_size)