Use standard hash functions in `mrb_hash_ht_hash_func`.

parent 78be0172
...@@ -20,37 +20,27 @@ mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) ...@@ -20,37 +20,27 @@ mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
{ {
enum mrb_vtype t = mrb_type(key); enum mrb_vtype t = mrb_type(key);
mrb_value hv; mrb_value hv;
const char *p;
mrb_int i, len;
khint_t h; khint_t h;
switch (t) { switch (t) {
case MRB_TT_STRING: case MRB_TT_STRING:
p = RSTRING_PTR(key); h = mrb_str_hash(mrb, key);
len = RSTRING_LEN(key); break;
h = 0;
for (i=0; i<len; i++) {
h = (h << 5) - h + *p++;
}
return h;
case MRB_TT_TRUE:
case MRB_TT_FALSE:
case MRB_TT_SYMBOL: case MRB_TT_SYMBOL:
h = (khint_t)mrb_symbol(key);
return kh_int_hash_func(mrb, h);
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
h = (khint_t)mrb_float_id((mrb_float)mrb_fixnum(key));
return kh_int_hash_func(mrb, h);
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
h = (khint_t)mrb_float_id(mrb_float(key)); h = (khint_t)mrb_obj_id(key);
return kh_int_hash_func(mrb, h); break;
default: default:
hv = mrb_funcall(mrb, key, "hash", 0); hv = mrb_funcall(mrb, key, "hash", 0);
h = (khint_t)t ^ mrb_fixnum(hv); h = (khint_t)t ^ mrb_fixnum(hv);
return kh_int_hash_func(mrb, h); break;
} }
return kh_int_hash_func(mrb, h);
} }
static inline khint_t static inline khint_t
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment