summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-11-18 12:09:16 +0100
committerJim Meyering <meyering@redhat.com>2011-11-18 16:00:44 +0100
commit2895f9dcb663cc11cd70395c98442574bc5df5fd (patch)
tree013a2179261899c01448c077e38bfec663f5efe8 /lib/hash.c
parentff37e81646b996b43d4635ddbb12c4e2654d544b (diff)
downloadgnulib-2895f9dcb663cc11cd70395c98442574bc5df5fd.tar.gz
hash: deprecate poorly-named hash_insert0: use hash_insert_if_absent
* lib/hash.c (hash_insert_if_absent): Rename from hash_insert0. Add a sentence to the comment. (hash_insert0): New function that simply calls hash_insert_if_absent. * lib/hash.h (hash_insert_if_absent): Declare it. (hash_insert0): Add deprecation attribute. (_GL_ATTRIBUTE_DEPRECATED): Define. * lib/di-set.c (di_set_insert): Use hash_insert_if_absent, not hash_insert0. * NEWS: Mention it, even though it's not really an incompatible change Prompted by a question from Matthew Booth <mbooth@redhat.com>.
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 4d76f765e9..0e44913609 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -1018,7 +1018,9 @@ hash_rehash (Hash_table *table, size_t candidate)
return false;
}
-/* Return -1 upon memory allocation failure.
+/* Insert ENTRY into hash TABLE if there is not already a matching entry.
+
+ Return -1 upon memory allocation failure.
Return 1 if insertion succeeded.
Return 0 if there is already a matching entry in the table,
and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT
@@ -1033,7 +1035,8 @@ hash_rehash (Hash_table *table, size_t candidate)
when the ENTRY value is a simple scalar, you must use hash_insert0.
ENTRY must not be NULL. */
int
-hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
+hash_insert_if_absent (Hash_table *table, void const *entry,
+ void const **matched_ent)
{
void *data;
struct hash_entry *bucket;
@@ -1113,6 +1116,14 @@ hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
return 1;
}
+/* hash_insert0 is the deprecated name for hash_insert_if_absent.
+ . */
+int
+hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
+{
+ return hash_insert_if_absent (table, entry, matched_ent);
+}
+
/* If ENTRY matches an entry already in the hash table, return the pointer
to the entry from the table. Otherwise, insert ENTRY and return ENTRY.
Return NULL if the storage required for insertion cannot be allocated.