summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-23 05:23:12 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-23 05:23:12 +0000
commitbf70582cf30ae6f715769c519f451411f5d2a577 (patch)
treeb3eb8e2975df384946ad70572e1e3387a6c3127c /st.c
parent6f82a67fd0035fcd2802f1564165d5211bc98ea2 (diff)
2000-02-23
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/st.c b/st.c
index 08651d0..9789cc7 100644
--- a/st.c
+++ b/st.c
@@ -111,6 +111,7 @@ new_size(size)
{
int i, newsize;
+#if 0
for (i = 0, newsize = MINSIZE;
i < sizeof(primes)/sizeof(primes[0]);
i++, newsize <<= 1)
@@ -119,6 +120,23 @@ new_size(size)
}
/* Ran out of polynomials */
return -1; /* should raise exception */
+#else
+ for (i=3; i<31; i++) {
+ if ((1<<i) > size) return 1<<i;
+ }
+ return -1;
+#endif
+}
+
+static int collision = 0;
+static int init_st = 0;
+
+static void
+stat_col()
+{
+ FILE *f = fopen("/tmp/col", "w");
+ fprintf(f, "collision: %d\n", collision);
+ fclose(f);
}
st_table*
@@ -128,6 +146,11 @@ st_init_table_with_size(type, size)
{
st_table *tbl;
+ if (init_st == 0) {
+ init_st = 1;
+ atexit(stat_col);
+ }
+
size = new_size(size); /* round up to prime number */
tbl = alloc(st_table);
@@ -198,6 +221,7 @@ st_free_table(table)
bin_pos = hash_val%(table)->num_bins;\
ptr = (table)->bins[bin_pos];\
if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
+ collision++;\
while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
ptr = ptr->next;\
}\