Created
August 29, 2009 23:47
-
-
Save methodmissing/177768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static int | |
| strhash(register const char *string) | |
| { | |
| register int c; | |
| register int val = 0; | |
| while ((c = *string++) != '\0') { | |
| val = val*997 + c; | |
| } | |
| return val + (val>>5); | |
| } | |
| int | |
| rb_sym_strhash(VALUE *sym) | |
| { | |
| ID id = SYM2ID(*sym); | |
| return strhash((char*)rb_id2name(id)); | |
| } | |
| static VALUE | |
| rb_sym_strhash_m(VALUE sym) | |
| { | |
| return INT2FIX(rb_sym_strhash(&sym)); | |
| } | |
| int | |
| rb_str_strhash(VALUE *str) | |
| { | |
| return strhash((char*)RSTRING_PTR(*str)); | |
| } | |
| static VALUE | |
| rb_str_strhash_m(VALUE str) | |
| { | |
| return INT2FIX(rb_str_strhash(&str)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment