summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
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;
}