Hi,
In message "[ruby-talk:16753] Re: Symbols, and their use as hash keys"
on 01/06/22, "Aristarkh A Zagorodnikov" <xm / w3d.ru> writes:
|> because "intern" is not free, I think. You called intern 10000 times
|> once for each symbol.
|The same stuff I did for string case, just not used them :)
Oops... That was caused by a bad hash function defined in st.c
Here's the patch.
matz.
--- st.c 2001/06/11 06:26:17 1.13.2.1
+++ st.c 2001/06/22 08:11:32
@@ -116,3 +116,3 @@
-#if 1
+#if 0
for (i=3; i<31; i++) {
@@ -233,3 +233,3 @@
#define FIND_ENTRY(table, ptr, hash_val, bin_pos) \
-bin_pos = hash_val&(table)->num_bins;\
+bin_pos = hash_val%(table)->num_bins;\
ptr = (table)->bins[bin_pos];\
@@ -268,3 +268,3 @@
rehash(table);\
- bin_pos = hash_val & table->num_bins;\
+ bin_pos = hash_val % table->num_bins;\
}\
@@ -311,3 +311,3 @@
hash_val = do_hash(key, table);
- bin_pos = hash_val & table->num_bins;
+ bin_pos = hash_val % table->num_bins;
ADD_DIRECT(table, key, value, hash_val, bin_pos);
@@ -331,3 +331,3 @@
next = ptr->next;
- hash_val = ptr->hash & new_num_bins;
+ hash_val = ptr->hash % new_num_bins;
ptr->next = new_bins[hash_val];
@@ -557,3 +557,3 @@
{
- return n/7;
+ return n;
}