/* This macro defines reserved value for empty table entry. */
-#define EMPTY_ENTRY ((void *) 0)
+#define EMPTY_ENTRY ((PTR) 0)
/* This macro defines reserved value for table entry which contained
a deleted element. */
-#define DELETED_ENTRY ((void *) 1)
+#define DELETED_ENTRY ((PTR) 1)
static unsigned long higher_prime_number PARAMS ((unsigned long));
static hashval_t hash_pointer PARAMS ((const void *));
static int eq_pointer PARAMS ((const void *, const void *));
static void htab_expand PARAMS ((htab_t));
-static void **find_empty_slot_for_expand PARAMS ((htab_t, hashval_t));
+static PTR *find_empty_slot_for_expand PARAMS ((htab_t, hashval_t));
/* At some point, we could make these be NULL, and modify the
hash-table routines to handle NULL specially; that would avoid
static hashval_t
hash_pointer (p)
- const void *p;
+ const PTR p;
{
return (hashval_t) ((long)p >> 3);
}
static int
eq_pointer (p1, p2)
- const void *p1;
- const void *p2;
+ const PTR p1;
+ const PTR p2;
{
return p1 == p2;
}
/* This function creates table with length slightly longer than given
source length. Created hash table is initiated as empty (all the
hash table entries are EMPTY_ENTRY). The function returns the
- created hash table. */
+ created hash table. */
htab_t
htab_create (size, hash_f, eq_f, del_f)
size = higher_prime_number (size);
result = (htab_t) xcalloc (1, sizeof (struct htab));
- result->entries = (void **) xcalloc (size, sizeof (void *));
+ result->entries = (PTR *) xcalloc (size, sizeof (PTR));
result->size = size;
result->hash_f = hash_f;
result->eq_f = eq_f;
&& htab->entries[i] != DELETED_ENTRY)
(*htab->del_f) (htab->entries[i]);
- memset (htab->entries, 0, htab->size * sizeof (void *));
+ memset (htab->entries, 0, htab->size * sizeof (PTR));
}
/* Similar to htab_find_slot, but without several unwanted side effects:
This function also assumes there are no deleted entries in the table.
HASH is the hash value for the element to be inserted. */
-static void **
+static PTR *
find_empty_slot_for_expand (htab, hash)
htab_t htab;
hashval_t hash;
for (;;)
{
- void **slot = htab->entries + index;
+ PTR *slot = htab->entries + index;
if (*slot == EMPTY_ENTRY)
return slot;
entries and repeatedly inserts the table elements. The occupancy
of the table after the call will be about 50%. Naturally the hash
table must already exist. Remember also that the place of the
- table entries is changed. */
+ table entries is changed. */
static void
htab_expand (htab)
htab_t htab;
{
- void **oentries;
- void **olimit;
- void **p;
+ PTR *oentries;
+ PTR *olimit;
+ PTR *p;
oentries = htab->entries;
olimit = oentries + htab->size;
htab->size = higher_prime_number (htab->size * 2);
- htab->entries = (void **) xcalloc (htab->size, sizeof (void **));
+ htab->entries = (PTR *) xcalloc (htab->size, sizeof (PTR *));
htab->n_elements -= htab->n_deleted;
htab->n_deleted = 0;
p = oentries;
do
{
- void *x = *p;
+ PTR x = *p;
if (x != EMPTY_ENTRY && x != DELETED_ENTRY)
{
- void **q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x));
+ PTR *q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x));
*q = x;
}
/* This function searches for a hash table entry equal to the given
element. It cannot be used to insert or delete an element. */
-void *
+PTR
htab_find_with_hash (htab, element, hash)
htab_t htab;
- const void *element;
+ const PTR element;
hashval_t hash;
{
unsigned int index;
hashval_t hash2;
size_t size;
- void *entry;
+ PTR entry;
htab->searches++;
size = htab->size;
/* Like htab_find_slot_with_hash, but compute the hash value from the
element. */
-void *
+PTR
htab_find (htab, element)
htab_t htab;
- const void *element;
+ const PTR element;
{
return htab_find_with_hash (htab, element, (*htab->hash_f) (element));
}
after doing some checks). To insert an entry, call this with
INSERT = 1, then write the value you want into the returned slot. */
-void **
+PTR *
htab_find_slot_with_hash (htab, element, hash, insert)
htab_t htab;
- const void *element;
+ const PTR element;
hashval_t hash;
enum insert_option insert;
{
- void **first_deleted_slot;
+ PTR *first_deleted_slot;
unsigned int index;
hashval_t hash2;
size_t size;
for (;;)
{
- void *entry = htab->entries[index];
+ PTR entry = htab->entries[index];
if (entry == EMPTY_ENTRY)
{
if (insert == NO_INSERT)
/* Like htab_find_slot_with_hash, but compute the hash value from the
element. */
-void **
+PTR *
htab_find_slot (htab, element, insert)
htab_t htab;
- const void *element;
+ const PTR element;
enum insert_option insert;
{
return htab_find_slot_with_hash (htab, element, (*htab->hash_f) (element),
void
htab_remove_elt (htab, element)
htab_t htab;
- void *element;
+ PTR element;
{
- void **slot;
+ PTR *slot;
slot = htab_find_slot (htab, element, NO_INSERT);
if (*slot == EMPTY_ENTRY)
void
htab_clear_slot (htab, slot)
htab_t htab;
- void **slot;
+ PTR *slot;
{
if (slot < htab->entries || slot >= htab->entries + htab->size
|| *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY)
htab_traverse (htab, callback, info)
htab_t htab;
htab_trav callback;
- void *info;
+ PTR info;
{
- void **slot = htab->entries;
- void **limit = slot + htab->size;
+ PTR *slot = htab->entries;
+ PTR *limit = slot + htab->size;
do
{
- void *x = *slot;
+ PTR x = *slot;
if (x != EMPTY_ENTRY && x != DELETED_ENTRY)
if (!(*callback) (slot, info))