summaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-30 03:02:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-30 03:02:35 +0000
commit0964b60f917392f7a827b3b2090cc2188d08f1fd (patch)
tree0b91be76f32fef5a10f318ed789117290ed6290f /numeric.c
parent969db0d06338570eff4f25778fe20a3e23369e54 (diff)
downloadruby-0964b60f917392f7a827b3b2090cc2188d08f1fd.tar.gz
ruby-0964b60f917392f7a827b3b2090cc2188d08f1fd.tar.xz
ruby-0964b60f917392f7a827b3b2090cc2188d08f1fd.zip
* numeric.c (flo_hash): improve collision.
* string.c (rb_memhash): new generic function to calculate hash value for memory chunk. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/numeric.c b/numeric.c
index 3000158be..255b6b52b 100644
--- a/numeric.c
+++ b/numeric.c
@@ -836,15 +836,11 @@ static VALUE
flo_hash(VALUE num)
{
double d;
- char *c;
- int i, hash;
+ int hash;
d = RFLOAT(num)->value;
if (d == 0) d = fabs(d);
- c = (char*)&d;
- for (hash=0, i=0; i<sizeof(double);i++) {
- hash += c[i] * 971;
- }
+ hash = rb_memhash(&d, sizeof(d)) ^ RBASIC(num)->klass;
if (hash < 0) hash = -hash;
return INT2FIX(hash);
}