summaryrefslogtreecommitdiff
path: root/libiberty/hashtab.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>1999-10-23 15:56:52 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>1999-10-23 15:56:52 +0000
commit21a7d507af929dfa8960de197a4fe936f5294c20 (patch)
tree3ad8d02ae08a5e2403f87cba3849031590ae8f60 /libiberty/hashtab.c
parenta7dea2456b830671cf6720f54876738c792eecdb (diff)
downloadgcc-21a7d507af929dfa8960de197a4fe936f5294c20.tar.gz
1999-10-23 08:51 -0700 Zack Weinberg <zack@bitmover.com>
* hashtab.c (find_hash_table_entry): When returning a DELETED_ENTRY slot, change it to EMPTY_ENTRY first. (clear_hash_table_slot): New function which deletes an entry by its position in the table, not its value. (traverse_hash_table): New function which calls a hook function for every live entry in the table. * hashtab.h: Give hash_table_t a struct tag. Add prototypes for clear_hash_table_slot and traverse_hash_table. Correct prototype of all_hash_table_collisions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@30138 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/hashtab.c')
-rw-r--r--libiberty/hashtab.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index 8137d77bc4e..9fce8ccc125 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -206,7 +206,7 @@ find_hash_table_entry (htab, element, reserve)
if (first_deleted_entry_ptr != NULL)
{
entry_ptr = first_deleted_entry_ptr;
- *entry_ptr = DELETED_ENTRY;
+ *entry_ptr = EMPTY_ENTRY;
}
}
break;
@@ -242,6 +242,41 @@ remove_element_from_hash_table_entry (htab, element)
htab->number_of_deleted_elements++;
}
+/* This function clears a specified slot in a hash table.
+ It is useful when you've already done the lookup and don't want to
+ do it again. */
+
+void
+clear_hash_table_slot (htab, slot)
+ hash_table_t htab;
+ hash_table_entry_t *slot;
+{
+ if (slot < htab->entries || slot >= htab->entries + htab->size
+ || *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY)
+ abort ();
+ *slot = DELETED_ENTRY;
+ htab->number_of_deleted_elements++;
+}
+
+/* This function scans over the entire hash table calling
+ CALLBACK for each live entry. If CALLBACK returns false,
+ the iteration stops. INFO is passed as CALLBACK's second
+ argument. */
+
+void
+traverse_hash_table (htab, callback, info)
+ hash_table_t htab;
+ int (*callback) (hash_table_entry_t, void *);
+ void *info;
+{
+ hash_table_entry_t *entry_ptr;
+ for (entry_ptr = htab->entries; entry_ptr < htab->entries + htab->size;
+ entry_ptr++)
+ if (*entry_ptr != EMPTY_ENTRY && *entry_ptr != DELETED_ENTRY)
+ if (!callback (*entry_ptr, info))
+ break;
+}
+
/* The following function returns current size of given hash table. */
size_t