* hashtab.c: Change void * to PTR where necessary.

(htab_create, htab_expand): Correct formatting of comment before
	function.
This commit is contained in:
Hans-Peter Nilsson 2000-11-03 20:55:25 +00:00
parent 6f72978879
commit e0f3df8f1e
2 changed files with 42 additions and 36 deletions

View File

@ -1,3 +1,9 @@
2000-11-03 Hans-Peter Nilsson <hp@bitrange.com>
* hashtab.c: Change void * to PTR where necessary.
(htab_create, htab_expand): Correct formatting of comment before
function.
2000-10-23 Alex Samuel <samuel@codesourcery.com> 2000-10-23 Alex Samuel <samuel@codesourcery.com>
* cp-demangle.c (string_list_def): Add caret_position and comments. * cp-demangle.c (string_list_def): Add caret_position and comments.

View File

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