summaryrefslogtreecommitdiff
path: root/gas/hash.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl@lucon.org>2005-04-29 16:56:12 +0000
committerH.J. Lu <hjl@lucon.org>2005-04-29 16:56:12 +0000
commit6d4986cdcad4a426d4b8cf4e0cf1a7bd5888c948 (patch)
tree32d61022b5334a195464017f97cf4ffa48d86831 /gas/hash.c
parentca1608659536f2ddc6ed516a27c1a58171cffc4e (diff)
downloadbinutils-redhat-6d4986cdcad4a426d4b8cf4e0cf1a7bd5888c948.tar.gz
2005-04-29 H.J. Lu <hongjiu.lu@intel.com>
* hash.c: Undo the last change. * hash.h: Likewise.
Diffstat (limited to 'gas/hash.c')
-rw-r--r--gas/hash.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/gas/hash.c b/gas/hash.c
index 29c97b94b3..bc534e67ad 100644
--- a/gas/hash.c
+++ b/gas/hash.c
@@ -294,6 +294,31 @@ hash_jam (struct hash_control *table, const char *key, PTR value)
return NULL;
}
+/* Replace an existing entry in a hash table. This returns the old
+ value stored for the entry. If the entry is not found in the hash
+ table, this does nothing and returns NULL. */
+
+PTR
+hash_replace (struct hash_control *table, const char *key, PTR value)
+{
+ struct hash_entry *p;
+ PTR ret;
+
+ p = hash_lookup (table, key, NULL, NULL);
+ if (p == NULL)
+ return NULL;
+
+#ifdef HASH_STATISTICS
+ ++table->replacements;
+#endif
+
+ ret = p->data;
+
+ p->data = value;
+
+ return ret;
+}
+
/* Find an entry in a hash table, returning its value. Returns NULL
if the entry is not found. */
@@ -309,6 +334,35 @@ hash_find (struct hash_control *table, const char *key)
return p->data;
}
+/* Delete an entry from a hash table. This returns the value stored
+ for that entry, or NULL if there is no such entry. */
+
+PTR
+hash_delete (struct hash_control *table, const char *key)
+{
+ struct hash_entry *p;
+ struct hash_entry **list;
+
+ p = hash_lookup (table, key, &list, NULL);
+ if (p == NULL)
+ return NULL;
+
+ if (p != *list)
+ abort ();
+
+#ifdef HASH_STATISTICS
+ ++table->deletions;
+#endif
+
+ *list = p->next;
+
+ /* Note that we never reclaim the memory for this entry. If gas
+ ever starts deleting hash table entries in a big way, this will
+ have to change. */
+
+ return p->data;
+}
+
/* Traverse a hash table. Call the function on every entry in the
hash table. */