diff options
author | Emilio G. Cota <cota@braap.org> | 2017-07-11 18:48:21 -0400 |
---|---|---|
committer | Richard Henderson <richard.henderson@linaro.org> | 2018-06-15 07:42:55 -1000 |
commit | 32359d529f30bea8124ed671b2e6a22f22540488 (patch) | |
tree | 937ee3f60e999574e764bcbf29f4aab1960cfe5b /include | |
parent | 61b8cef1d42567d3029e0c7180cbd0f16cc4be2d (diff) | |
download | qemu-32359d529f30bea8124ed671b2e6a22f22540488.zip qemu-32359d529f30bea8124ed671b2e6a22f22540488.tar.gz qemu-32359d529f30bea8124ed671b2e6a22f22540488.tar.bz2 |
qht: return existing entry when qht_insert fails
The meaning of "existing" is now changed to "matches in hash and
ht->cmp result". This is saner than just checking the pointer value.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/qht.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/qemu/qht.h b/include/qemu/qht.h index 5f03a0f..1fb9116 100644 --- a/include/qemu/qht.h +++ b/include/qemu/qht.h @@ -70,6 +70,7 @@ void qht_destroy(struct qht *ht); * @ht: QHT to insert to * @p: pointer to be inserted * @hash: hash corresponding to @p + * @existing: address where the pointer to an existing entry can be copied to * * Attempting to insert a NULL @p is a bug. * Inserting the same pointer @p with different @hash values is a bug. @@ -78,9 +79,11 @@ void qht_destroy(struct qht *ht); * inserted into the hash table. * * Returns true on success. - * Returns false if the @p-@hash pair already exists in the hash table. + * Returns false if there is an existing entry in the table that is equivalent + * (i.e. ht->cmp matches and the hash is the same) to @p-@h. If @existing + * is !NULL, a pointer to this existing entry is copied to it. */ -bool qht_insert(struct qht *ht, void *p, uint32_t hash); +bool qht_insert(struct qht *ht, void *p, uint32_t hash, void **existing); /** * qht_lookup_custom - Look up a pointer using a custom comparison function. |