summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--intern.h1
-rw-r--r--numeric.c8
-rw-r--r--string.c17
4 files changed, 21 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 435a9b184f..006e088ee6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Aug 30 12:01:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (flo_hash): improve collision.
+
+ * string.c (rb_memhash): new generic function to calculate hash value
+ for memory chunk.
+
Tue Aug 29 19:10:10 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* hash.c (rb_hash_s_create): fixed memory leak, based on the patch
diff --git a/intern.h b/intern.h
index 04fbf7f113..5a941b6627 100644
--- a/intern.h
+++ b/intern.h
@@ -502,6 +502,7 @@ VALUE rb_str_cat(VALUE, const char*, long);
VALUE rb_str_cat2(VALUE, const char*);
VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
+int rb_memhash(const void *ptr, long len);
int rb_str_hash(VALUE);
int rb_str_cmp(VALUE, VALUE);
VALUE rb_str_upto(VALUE, VALUE, int);
diff --git a/numeric.c b/numeric.c
index 3000158be1..255b6b52b4 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);
}
diff --git a/string.c b/string.c
index ef065b831f..f6eda3745b 100644
--- a/string.c
+++ b/string.c
@@ -768,9 +768,9 @@ rb_str_concat(VALUE str1, VALUE str2)
/*
* hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code
*
- * @(#) $Revision$
- * @(#) $Id$
- * @(#) $Source$
+ * @(#) $hash_32.Revision: 1.1 $
+ * @(#) $hash_32.Id: hash_32a.c,v 1.1 2003/10/03 20:38:53 chongo Exp $
+ * @(#) $hash_32.Source: /usr/local/src/cmd/fnv/RCS/hash_32a.c,v $
*
***
*
@@ -841,10 +841,9 @@ rb_str_concat(VALUE str1, VALUE str2)
#define FNV_32_PRIME 0x01000193
int
-rb_str_hash(VALUE str)
+rb_memhash(const void *ptr, long len)
{
- register long len = RSTRING(str)->len;
- register char *p = RSTRING(str)->ptr;
+ register const unsigned char *p = ptr;
register unsigned int hval = FNV1_32A_INIT;
/*
@@ -864,6 +863,12 @@ rb_str_hash(VALUE str)
return hval;
}
+int
+rb_str_hash(VALUE str)
+{
+ return rb_memhash(RSTRING(str)->ptr, RSTRING(str)->len);
+}
+
/*
* call-seq:
* str.hash => fixnum