Skip to content

Instantly share code, notes, and snippets.

@arya
Created December 4, 2009 01:03
Show Gist options
  • Save arya/248747 to your computer and use it in GitHub Desktop.
Save arya/248747 to your computer and use it in GitHub Desktop.
int
rb_str_hash(str)
VALUE str;
{
register long len = RSTRING(str)->len;
register char *p = RSTRING(str)->ptr;
register int key = 0;
#if defined(HASH_ELFHASH)
register unsigned int g;
while (len--) {
key = (key << 4) + *p++;
if (g = key & 0xF0000000)
key ^= g >> 24;
key &= ~g;
}
#elif defined(HASH_PERL)
while (len--) {
key += *p++;
key += (key << 10);
key ^= (key >> 6);
}
key += (key << 3);
key ^= (key >> 11);
key += (key << 15);
#else
while (len--) {
key = key*65599 + *p;
p++;
}
key = key + (key>>5);
#endif
return key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment