diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-10 00:00:24 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-10 00:00:24 +0000 |
commit | 3fdd387aa3260f73485373dcc6726c6fe907f4c0 (patch) | |
tree | 1c8555764b859bc239b43c7b7d97a90239ceeb2a /libiberty/hashtab.c | |
parent | 19e447101e84dfd5c6e398207ac6a25c5f49d046 (diff) | |
download | gcc-3fdd387aa3260f73485373dcc6726c6fe907f4c0.tar.gz |
* hashtab.h (struct htab): Add del_f.
(htab_del): New type.
(htab_create): Add fourth argument.
* hashtab.c (htab_create): Set del_f.
(htab_delete, htab_empty, htab_remove_elt, htab_clear_slot):
Use it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32459 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/hashtab.c')
-rw-r--r-- | libiberty/hashtab.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c index ea9f9d38ac7..0bc9e485ef0 100644 --- a/libiberty/hashtab.c +++ b/libiberty/hashtab.c @@ -88,10 +88,11 @@ higher_prime_number (n) created hash table. */ htab_t -htab_create (size, hash_f, eq_f) +htab_create (size, hash_f, eq_f, del_f) size_t size; htab_hash hash_f; htab_eq eq_f; + htab_del del_f; { htab_t result; @@ -101,6 +102,7 @@ htab_create (size, hash_f, eq_f) result->size = size; result->hash_f = hash_f; result->eq_f = eq_f; + result->del_f = del_f; return result; } @@ -111,6 +113,15 @@ void htab_delete (htab) htab_t htab; { + int i; + if (htab->del_f) + for (i = htab->size - 1; i >= 0; i--) + { + if (htab->entries[i] != EMPTY_ENTRY + && htab->entries[i] != DELETED_ENTRY) + (*htab->del_f) (htab->entries[i]); + } + free (htab->entries); free (htab); } @@ -121,6 +132,15 @@ void htab_empty (htab) htab_t htab; { + int i; + if (htab->del_f) + for (i = htab->size - 1; i >= 0; i--) + { + if (htab->entries[i] != EMPTY_ENTRY + && htab->entries[i] != DELETED_ENTRY) + (*htab->del_f) (htab->entries[i]); + } + memset (htab->entries, 0, htab->size * sizeof (void *)); } @@ -273,6 +293,9 @@ htab_remove_elt (htab, element) if (*slot == EMPTY_ENTRY) return; + if (htab->del_f) + (*htab->del_f) (*slot); + *slot = DELETED_ENTRY; htab->n_deleted++; } @@ -289,6 +312,8 @@ htab_clear_slot (htab, slot) if (slot < htab->entries || slot >= htab->entries + htab->size || *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY) abort (); + if (htab->del_f) + (*htab->del_f) (*slot); *slot = DELETED_ENTRY; htab->n_deleted++; } |