summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c74
1 files changed, 19 insertions, 55 deletions
diff --git a/hash.c b/hash.c
index 9083b60..5eed69c 100644
--- a/hash.c
+++ b/hash.c
@@ -41,12 +41,8 @@ void *hash_deleted_item = &hash_deleted_item;
given size. */
void
-hash_init (ht, size, hash_1, hash_2, hash_cmp)
- struct hash_table* ht;
- unsigned long size;
- hash_func_t hash_1;
- hash_func_t hash_2;
- hash_cmp_func_t hash_cmp;
+hash_init (struct hash_table *ht, unsigned long size,
+ hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp)
{
ht->ht_size = round_up_2 (size);
ht->ht_empty_slots = ht->ht_size;
@@ -71,11 +67,8 @@ hash_init (ht, size, hash_1, hash_2, hash_cmp)
/* Load an array of items into `ht'. */
void
-hash_load (ht, item_table, cardinality, size)
- struct hash_table* ht;
- void *item_table;
- unsigned long cardinality;
- unsigned long size;
+hash_load (struct hash_table *ht, void *item_table,
+ unsigned long cardinality, unsigned long size)
{
char *items = (char *) item_table;
while (cardinality--)
@@ -91,9 +84,7 @@ hash_load (ht, item_table, cardinality, size)
ht_fill on insertion. */
void **
-hash_find_slot (ht, key)
- struct hash_table* ht;
- void const *key;
+hash_find_slot (struct hash_table *ht, const void *key)
{
void **slot;
void **deleted_slot = 0;
@@ -128,18 +119,14 @@ hash_find_slot (ht, key)
}
void *
-hash_find_item (ht, key)
- struct hash_table* ht;
- void const *key;
+hash_find_item (struct hash_table *ht, const void *key)
{
void **slot = hash_find_slot (ht, key);
return ((HASH_VACANT (*slot)) ? 0 : *slot);
}
void *
-hash_insert (ht, item)
- struct hash_table* ht;
- void *item;
+hash_insert (struct hash_table *ht, void *item)
{
void **slot = hash_find_slot (ht, item);
void *old_item = slot ? *slot : 0;
@@ -148,10 +135,7 @@ hash_insert (ht, item)
}
void *
-hash_insert_at (ht, item, slot)
- struct hash_table* ht;
- void *item;
- void const *slot;
+hash_insert_at (struct hash_table *ht, void *item, const void *slot)
{
void *old_item = *(void **) slot;
if (HASH_VACANT (old_item))
@@ -172,18 +156,14 @@ hash_insert_at (ht, item, slot)
}
void *
-hash_delete (ht, item)
- struct hash_table* ht;
- void const *item;
+hash_delete (struct hash_table *ht, const void *item)
{
void **slot = hash_find_slot (ht, item);
return hash_delete_at (ht, slot);
}
void *
-hash_delete_at (ht, slot)
- struct hash_table* ht;
- void const *slot;
+hash_delete_at (struct hash_table *ht, const void *slot)
{
void *item = *(void **) slot;
if (!HASH_VACANT (item))
@@ -197,8 +177,7 @@ hash_delete_at (ht, slot)
}
void
-hash_free_items (ht)
- struct hash_table* ht;
+hash_free_items (struct hash_table *ht)
{
void **vec = ht->ht_vec;
void **end = &vec[ht->ht_size];
@@ -214,8 +193,7 @@ hash_free_items (ht)
}
void
-hash_delete_items (ht)
- struct hash_table* ht;
+hash_delete_items (struct hash_table *ht)
{
void **vec = ht->ht_vec;
void **end = &vec[ht->ht_size];
@@ -229,9 +207,7 @@ hash_delete_items (ht)
}
void
-hash_free (ht, free_items)
- struct hash_table* ht;
- int free_items;
+hash_free (struct hash_table *ht, int free_items)
{
if (free_items)
hash_free_items (ht);
@@ -246,9 +222,7 @@ hash_free (ht, free_items)
}
void
-hash_map (ht, map)
- struct hash_table *ht;
- hash_map_func_t map;
+hash_map (struct hash_table *ht, hash_map_func_t map)
{
void **slot;
void **end = &ht->ht_vec[ht->ht_size];
@@ -261,10 +235,7 @@ hash_map (ht, map)
}
void
-hash_map_arg (ht, map, arg)
- struct hash_table *ht;
- hash_map_arg_func_t map;
- void *arg;
+hash_map_arg (struct hash_table *ht, hash_map_arg_func_t map, void *arg)
{
void **slot;
void **end = &ht->ht_vec[ht->ht_size];
@@ -279,8 +250,7 @@ hash_map_arg (ht, map, arg)
/* Double the size of the hash table in the event of overflow... */
static void
-hash_rehash (ht)
- struct hash_table* ht;
+hash_rehash (struct hash_table *ht)
{
unsigned long old_ht_size = ht->ht_size;
void **old_vec = ht->ht_vec;
@@ -307,9 +277,7 @@ hash_rehash (ht)
}
void
-hash_print_stats (ht, out_FILE)
- struct hash_table *ht;
- FILE *out_FILE;
+hash_print_stats (struct hash_table *ht, FILE *out_FILE)
{
/* GKM FIXME: honor NO_FLOAT */
fprintf (out_FILE, _("Load=%ld/%ld=%.0f%%, "), ht->ht_fill, ht->ht_size,
@@ -325,10 +293,7 @@ hash_print_stats (ht, out_FILE)
user-supplied vector, or malloc one. */
void **
-hash_dump (ht, vector_0, compare)
- struct hash_table *ht;
- void **vector_0;
- qsort_cmp_t compare;
+hash_dump (struct hash_table *ht, void **vector_0, qsort_cmp_t compare)
{
void **vector;
void **slot;
@@ -351,8 +316,7 @@ hash_dump (ht, vector_0, compare)
/* Round a given number up to the nearest power of 2. */
static unsigned long
-round_up_2 (n)
- unsigned long n;
+round_up_2 (unsigned long n)
{
n |= (n >> 1);
n |= (n >> 2);