Mercurial > hg > octave-nkf > gnulib-hg
comparison lib/hash.c @ 16096:13817d3d0af6
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>.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Fri, 18 Nov 2011 12:09:16 +0100 |
parents | 157bb0cdd13a |
children | deba2a70b794 |
comparison
equal
deleted
inserted
replaced
16095:02a734ccfb9a | 16096:13817d3d0af6 |
---|---|
1016 /* table->n_entries already holds its value. */ | 1016 /* table->n_entries already holds its value. */ |
1017 free (new_table->bucket); | 1017 free (new_table->bucket); |
1018 return false; | 1018 return false; |
1019 } | 1019 } |
1020 | 1020 |
1021 /* Return -1 upon memory allocation failure. | 1021 /* Insert ENTRY into hash TABLE if there is not already a matching entry. |
1022 | |
1023 Return -1 upon memory allocation failure. | |
1022 Return 1 if insertion succeeded. | 1024 Return 1 if insertion succeeded. |
1023 Return 0 if there is already a matching entry in the table, | 1025 Return 0 if there is already a matching entry in the table, |
1024 and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT | 1026 and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT |
1025 to that entry. | 1027 to that entry. |
1026 | 1028 |
1031 the return value and ENTRY. That works only when you can have two | 1033 the return value and ENTRY. That works only when you can have two |
1032 different ENTRY values that point to data that compares "equal". Thus, | 1034 different ENTRY values that point to data that compares "equal". Thus, |
1033 when the ENTRY value is a simple scalar, you must use hash_insert0. | 1035 when the ENTRY value is a simple scalar, you must use hash_insert0. |
1034 ENTRY must not be NULL. */ | 1036 ENTRY must not be NULL. */ |
1035 int | 1037 int |
1036 hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent) | 1038 hash_insert_if_absent (Hash_table *table, void const *entry, |
1039 void const **matched_ent) | |
1037 { | 1040 { |
1038 void *data; | 1041 void *data; |
1039 struct hash_entry *bucket; | 1042 struct hash_entry *bucket; |
1040 | 1043 |
1041 /* The caller cannot insert a NULL entry, since hash_lookup returns NULL | 1044 /* The caller cannot insert a NULL entry, since hash_lookup returns NULL |
1109 bucket->data = (void *) entry; | 1112 bucket->data = (void *) entry; |
1110 table->n_entries++; | 1113 table->n_entries++; |
1111 table->n_buckets_used++; | 1114 table->n_buckets_used++; |
1112 | 1115 |
1113 return 1; | 1116 return 1; |
1117 } | |
1118 | |
1119 /* hash_insert0 is the deprecated name for hash_insert_if_absent. | |
1120 . */ | |
1121 int | |
1122 hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent) | |
1123 { | |
1124 return hash_insert_if_absent (table, entry, matched_ent); | |
1114 } | 1125 } |
1115 | 1126 |
1116 /* If ENTRY matches an entry already in the hash table, return the pointer | 1127 /* If ENTRY matches an entry already in the hash table, return the pointer |
1117 to the entry from the table. Otherwise, insert ENTRY and return ENTRY. | 1128 to the entry from the table. Otherwise, insert ENTRY and return ENTRY. |
1118 Return NULL if the storage required for insertion cannot be allocated. | 1129 Return NULL if the storage required for insertion cannot be allocated. |