Mercurial > hg > xemacs-beta
diff src/hash.c @ 410:de805c49cfc1 r21-2-35
Import from CVS: tag r21-2-35
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:19:21 +0200 |
parents | 74fd4e045ea6 |
children | 697ef44129c6 |
line wrap: on
line diff
--- a/src/hash.c Mon Aug 13 11:18:12 2007 +0200 +++ b/src/hash.c Mon Aug 13 11:19:21 2007 +0200 @@ -52,6 +52,25 @@ 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)