Permalink
Browse files

use murmur hash

  • Loading branch information...
1 parent 73bdff6 commit 506209ea4c4e6bd6ccaba406c100e4aaaabbb5f6 @Watson1978 Watson1978 committed Jan 3, 2012
Showing with 10 additions and 8 deletions.
  1. +6 −4 range.c
  2. +4 −4 struct.c
View
@@ -233,14 +233,16 @@ range_eql(VALUE range, SEL sel, VALUE obj)
static VALUE
range_hash(VALUE range, SEL sel)
{
- long hash = EXCL(range);
+ st_index_t hash = EXCL(range);
VALUE v;
+ hash = rb_hash_start(hash);
v = rb_hash(RANGE_BEG(range));
- hash ^= v << 1;
+ hash = rb_hash_uint(hash, NUM2LONG(v));
v = rb_hash(RANGE_END(range));
- hash ^= v << 9;
- hash ^= EXCL(range) << 24;
+ hash = rb_hash_uint(hash, NUM2LONG(v));
+ hash = rb_hash_uint(hash, EXCL(range) << 24);
+ hash = rb_hash_end(hash);
return LONG2FIX(hash);
}
View
@@ -879,17 +879,17 @@ rb_struct_hash_r(VALUE s, VALUE s2, int recur)
st_index_t h;
VALUE n, *ptr;
- h = rb_hash(rb_obj_class(s));
+ h = rb_hash_start(rb_hash(rb_obj_class(s)));
if (!recur) {
ptr = RSTRUCT_PTR(s);
len = RSTRUCT_LEN(s);
for (i = 0; i < len; i++) {
- h = (h << 1);
n = rb_hash(ptr[i]);
- h ^= NUM2LONG(n);
+ h = rb_hash_uint(h, NUM2LONG(n));
}
}
- return LONG2FIX(h);
+ h = rb_hash_end(h);
+ return INT2FIX(h);
}
/*

0 comments on commit 506209e

Please sign in to comment.