summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-06-22 09:12:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-06-22 09:12:24 +0000
commitdef42c9a0cd274202da56531c19e0a4bee3364e3 (patch)
treeb100f68b08e5f1ae5338055ae798320a4a339e01 /st.c
parentef8e0b4dffaec6789a1582d841ddb563cac2115d (diff)
* eval.c (rb_yield_0): no mvalue_to_svalue conversion here.
* eval.c (massign): takes svalue, convert it to mvalue inside. * eval.c (rb_eval): parameters for yield/return are always svalues now. * eval.c (svalue_to_mvalue): more strict conversion. * eval.c (mvalue_to_svalue): ditto. * st.c (new_size): prime hash size enabled. * ext/socket/socket.c (Init_socket): SO_* constants added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/st.c b/st.c
index f20549307f..c1e4e3bec8 100644
--- a/st.c
+++ b/st.c
@@ -65,7 +65,7 @@ static void rehash();
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
-#define do_hash_bin(key,table) (do_hash(key, table)&(table)->num_bins)
+#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
/*
* MINSIZE is the minimum size of a dictionary.
@@ -114,12 +114,14 @@ new_size(size)
{
int i;
-#if 1
+#if 0
for (i=3; i<31; i++) {
if ((1<<i) > size) return 1<<i;
}
return -1;
#else
+ int newsize;
+
for (i = 0, newsize = MINSIZE;
i < sizeof(primes)/sizeof(primes[0]);
i++, newsize <<= 1)
@@ -231,7 +233,7 @@ st_free_table(table)
#endif
#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];\
if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
COLLISION;\
@@ -267,7 +269,7 @@ st_lookup(table, key, value)
st_table_entry *entry;\
if (table->num_entries/(table->num_bins+1) > ST_DEFAULT_MAX_DENSITY) {\
rehash(table);\
- bin_pos = hash_val & table->num_bins;\
+ bin_pos = hash_val % table->num_bins;\
}\
\
entry = alloc(st_table_entry);\
@@ -311,7 +313,7 @@ st_add_direct(table, key, value)
unsigned int hash_val, bin_pos;
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,7 +333,7 @@ rehash(table)
ptr = table->bins[i];
while (ptr != 0) {
next = ptr->next;
- hash_val = ptr->hash & new_num_bins;
+ hash_val = ptr->hash % new_num_bins;
ptr->next = new_bins[hash_val];
new_bins[hash_val] = ptr;
ptr = next;
@@ -558,5 +560,5 @@ static int
numhash(n)
long n;
{
- return n / 7;
+ return n;
}