diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-03-10 00:00:24 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-03-10 00:00:24 +0000 |
commit | 5dc9cffdfd6fb65d46193fe95b3f6ecea1242b7d (patch) | |
tree | 1c8555764b859bc239b43c7b7d97a90239ceeb2a /libiberty/hashtab.c | |
parent | aa77ac5f237e2b0a646631ec7088b8c7bdd14fd3 (diff) | |
download | gcc-5dc9cffdfd6fb65d46193fe95b3f6ecea1242b7d.tar.gz |
hashtab.h (struct htab): Add del_f.
* 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.
From-SVN: r32459
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++; } |