diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2005-04-29 16:56:12 +0000 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2005-04-29 16:56:12 +0000 |
commit | 7e70f1afa7a6e5d343057db95bbfbe30701a2911 (patch) | |
tree | e61f9c49b93527cd42a401aa60aa13a7cd6639f7 /gas | |
parent | cba1200696dfad3a4748d3bf01b98f156bdfc3a2 (diff) | |
download | gdb-7e70f1afa7a6e5d343057db95bbfbe30701a2911.zip gdb-7e70f1afa7a6e5d343057db95bbfbe30701a2911.tar.gz gdb-7e70f1afa7a6e5d343057db95bbfbe30701a2911.tar.bz2 |
2005-04-29 H.J. Lu <hongjiu.lu@intel.com>
* hash.c: Undo the last change.
* hash.h: Likewise.
Diffstat (limited to 'gas')
-rw-r--r-- | gas/ChangeLog | 5 | ||||
-rw-r--r-- | gas/hash.c | 54 | ||||
-rw-r--r-- | gas/hash.h | 12 |
3 files changed, 71 insertions, 0 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index 23c63e9..6e004e6 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,8 @@ +2005-04-29 H.J. Lu <hongjiu.lu@intel.com> + + * hash.c: Undo the last change. + * hash.h: Likewise. + 2005-04-29 Ben Elliston <bje@au.ibm.com> * Makefile.am (GAS_CFILES): Remove bignum-copy.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. */ @@ -51,11 +51,23 @@ extern const char *hash_insert (struct hash_control *, extern const char *hash_jam (struct hash_control *, const char *key, PTR value); +/* 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. */ + +extern PTR hash_replace (struct hash_control *, const char *key, + PTR value); + /* Find an entry in a hash table, returning its value. Returns NULL if the entry is not found. */ extern PTR hash_find (struct hash_control *, const char *key); +/* Delete an entry from a hash table. This returns the value stored + for that entry, or NULL if there is no such entry. */ + +extern PTR hash_delete (struct hash_control *, const char *key); + /* Traverse a hash table. Call the function on every entry in the hash table. */ |