#include "config.h"
-#if defined (HAVE_STRING_H)
-# include <string.h>
-#else /* !HAVE_STRING_H */
-# include <strings.h>
-#endif /* !HAVE_STRING_H */
-
-#if defined (HAVE_STDLIB_H)
-# include <stdlib.h>
-#else
-# include "ansi_stdlib.h"
-#endif /* HAVE_STDLIB_H */
+#include "bashansi.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
+#include <stdio.h>
+
#include "shell.h"
#include "hashlib.h"
int i;
register BUCKET_CONTENTS *bucket, *item;
+ if (table == 0)
+ return;
+
for (i = 0; i < table->nbuckets; i++)
{
bucket = table->bucket_array[i];
}
}
+/* Free the hash table pointed to by TABLE. */
+void
+dispose_hash_table (table)
+ HASH_TABLE *table;
+{
+ free (table->bucket_array);
+ free (table);
+}
+
/* Return the bucket_contents list of bucket BUCKET in TABLE. If
TABLE doesn't have BUCKET buckets, return NULL. */
#undef get_hash_bucket
return (BUCKET_CONTENTS *)NULL;
}
+/* #ifdef DEBUG */
+print_table_stats (table, name)
+ HASH_TABLE *table;
+ char *name;
+{
+ register int slot, bcount;
+ register BUCKET_CONTENTS *bc;
+
+ if (name == 0)
+ name = "unknown hash table";
+
+ fprintf (stderr, "%s: %d buckets; %d items\n", name, table->nbuckets, table->nentries);
+
+ /* Print out a count of how many strings hashed to each bucket, so we can
+ see how even the distribution is. */
+ for (slot = 0; slot < table->nbuckets; slot++)
+ {
+ bc = get_hash_bucket (slot, table);
+
+ fprintf (stderr, "\tslot %3d: ", slot);
+ for (bcount = 0; bc; bc = bc->next)
+ bcount++;
+
+ fprintf (stderr, "%d\n", bcount);
+ }
+}
+/* #endif */
+
#ifdef TEST_HASHING
#undef NULL
}
}
- printf ("You have entered %d (%d) items. The distribution is:\n",
- table->nentries, count);
-
- /* Print out a count of how many strings hashed to each bucket, so we can
- see how even the distribution is. */
- for (count = 0; count < table->nbuckets; count++)
- {
- int bcount;
- register BUCKET_CONTENTS *list = get_hash_bucket (count, table);
-
- printf ("slot %3d: ", count);
- bcount = 0;
-
- for (bcount = 0; list; list = list->next)
- bcount++;
-
- printf ("%d\n", bcount);
- }
- exit (0);
+ print_table_stats (table, "hash test");
+ exit (0);
}
#endif /* TEST_HASHING */