]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hashtab.c (find_hash_table_entry): When returning a DELETED_ENTRY slot, change it...
authorZack Weinberg <zack@bitmover.com>
Sat, 23 Oct 1999 15:56:52 +0000 (15:56 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Sat, 23 Oct 1999 15:56:52 +0000 (15:56 +0000)
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.

From-SVN: r30138

include/ChangeLog
include/hashtab.h
libiberty/ChangeLog
libiberty/hashtab.c

index cfaab0aac81661ddf780f4d3fdc5ddd84f66d945..545574f9f27ee6dc6fd6e6b7280f2336b021767a 100644 (file)
@@ -1,3 +1,9 @@
+1999-10-23 08:51 -0700  Zack Weinberg  <zack@bitmover.com>
+
+       * 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.
+
 Fri Oct 15 01:47:51 1999  Vladimir Makarov  <vmakarov@loony.cygnus.com>
 
        * hashtab.h: New file.
index 67c37a284f771077e08410ab5d6e935556377531..3990c14cbcaaad318c1a74d8dfea696ed5995b6b 100644 (file)
@@ -47,7 +47,7 @@ typedef const void *hash_table_entry_t;
    tables.  All work with hash table should be executed only through
    functions mentioned below. */
 
-typedef struct
+typedef struct hash_table
 {
   /* Current size (in entries) of the hash table */
   size_t size;
@@ -88,13 +88,19 @@ extern hash_table_entry_t *find_hash_table_entry
 extern void remove_element_from_hash_table_entry PARAMS ((hash_table_t,
                                                          hash_table_entry_t));
 
+extern void clear_hash_table_slot PARAMS ((hash_table_t, hash_table_entry_t *));
+
+extern void traverse_hash_table PARAMS ((hash_table_t,
+                                        int (*) (hash_table_entry_t, void *),
+                                        void *));
+    
 extern size_t hash_table_size PARAMS ((hash_table_t));
 
 extern size_t hash_table_elements_number PARAMS ((hash_table_t));
 
 extern int hash_table_collisions PARAMS ((hash_table_t));
 
-extern int all_hash_table_collisions ();
+extern int all_hash_table_collisions PARAMS ((void));
 
 #ifdef __cplusplus
 }
index 78180af2d5dc826eede2918ab07127e1311184f8..829b70ed19f57e9e1296ee3b8276d6ed44c67c17 100644 (file)
@@ -1,3 +1,12 @@
+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.
+
 1999-10-19  Mark Mitchell  <mark@codesourcery.com>
 
        * cplus-dem.c (INTBUF_SIZE): New macro.
index 8137d77bc4e2dab1a3a13614e24ffea463ccc0cf..9fce8ccc1254f2f243a07e246b6c7572957ec658 100644 (file)
@@ -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