summaryrefslogtreecommitdiffhomepage
path: root/src/hash.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-09 11:49:26 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-09 11:49:26 +0900
commit63cf7073de6e9341e18b323f679afead2bacd924 (patch)
treeb9619b6928ddce61e297184af26582caae9eb5f8 /src/hash.c
parentd95d55089de26784f78e66700d55bf858f1be0c2 (diff)
downloadmruby-63cf7073de6e9341e18b323f679afead2bacd924.tar.gz
mruby-63cf7073de6e9341e18b323f679afead2bacd924.zip
improve hash function based on #2027; close #2027
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/hash.c b/src/hash.c
index 93f0650dd..0090dc5dd 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -28,28 +28,29 @@ mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
case MRB_TT_STRING:
p = RSTRING_PTR(key);
len = RSTRING_LEN(key);
- break;
+ h = 0;
+ for (i=0; i<len; i++) {
+ h = (h << 5) - h + *p++;
+ }
+ return h;
case MRB_TT_SYMBOL:
- p = mrb_sym2name_len(mrb, mrb_symbol(key), &len);
- break;
+ h = (khint_t)mrb_symbol(key);
+ return kh_int_hash_func(mrb,h);
case MRB_TT_FIXNUM:
- return (khint_t)mrb_float_id((mrb_float)mrb_fixnum(key));
+ h = (khint_t)mrb_float_id((mrb_float)mrb_fixnum(key));
+ return kh_int_hash_func(mrb,h);
case MRB_TT_FLOAT:
- return (khint_t)mrb_float_id(mrb_float(key));
+ h = (khint_t)mrb_float_id(mrb_float(key));
+ return kh_int_hash_func(mrb,h);
default:
hv = mrb_funcall(mrb, key, "hash", 0);
- return (khint_t)t ^ mrb_fixnum(hv);
- }
-
- h = 0;
- for (i=0; i<len; i++) {
- h = (h << 5) - h + *p++;
+ h = (khint_t)t ^ mrb_fixnum(hv);
+ return kh_int_hash_func(mrb,h);
}
- return h;
}
static inline khint_t