X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Fhash.c;h=41b9570e0b853c474b338ebe0bd8b731e4852ab9;hp=71e3b44670cc83969a6b46ad1184026f5e46c9d1;hb=762383636a99307282c2d93d26c35c046ec24da1;hpb=e31bfd1501359ce20fe1caf6b913a019318ec83c 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)