summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-21 09:18:05 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-21 09:18:05 +0000
commit334b2c9f855ca8e4a36d34c6e600f5203ec017a5 (patch)
tree81a3e8889b938217aa68284686b38313241c3f9e /st.c
parent043ec1f18d6e99b73eec029142185019f383f478 (diff)
st.c(rehash)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/st.c b/st.c
index 27ccf3e..eefa849 100644
--- a/st.c
+++ b/st.c
@@ -49,6 +49,7 @@ static void rehash();
#define EQUAL(table, x, y) ((*table->type->compare)(x, y) == 0)
#define do_hash(key, table) (*(table)->type->hash)((key), (table)->num_bins)
+#define do_hash2(key, table, bins) (*(table)->type->hash)((key), bins)
st_table*
st_init_table_with_size(type, size)
@@ -222,29 +223,31 @@ rehash(table)
register st_table *table;
{
register st_table_entry *ptr, *next, **old_bins = table->bins;
- int i, old_num_bins = table->num_bins, hash_val;
+ int i, old_num_bins = table->num_bins, new_num_bins, hash_val;
- table->num_bins = 1.79*old_num_bins;
+ new_num_bins = 1.79*old_num_bins;
- if (table->num_bins%2 == 0) {
- table->num_bins += 1;
+ if (new_num_bins%2 == 0) {
+ new_num_bins += 1;
}
+ table->num_bins = 0;
table->num_entries = 0;
table->bins = (st_table_entry **)
- Calloc((unsigned)table->num_bins, sizeof(st_table_entry*));
+ Calloc((unsigned)new_num_bins, sizeof(st_table_entry*));
for(i = 0; i < old_num_bins ; i++) {
ptr = old_bins[i];
while (ptr != nil(st_table_entry)) {
next = ptr->next;
- hash_val = do_hash(ptr->key, table);
+ hash_val = do_hash2(ptr->key, table, new_num_bins);
ptr->next = table->bins[hash_val];
table->bins[hash_val] = ptr;
table->num_entries++;
ptr = next;
}
}
+ table->num_bins = new_num_bins;
free((char*)old_bins);
}