diff options
author | Jason Ekstrand <[email protected]> | 2014-11-24 22:19:50 -0800 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2014-12-14 19:32:53 -0800 |
commit | 94303a0750f9eaae3fcf598b7bf1320e521898fb (patch) | |
tree | 34bd7bea6b61d60c94731333e31ffdca21205a29 /src/util/tests/hash_table/replacement.c | |
parent | 0d7f4c8658e00d30a1b0c3f2d803378eaa0717c7 (diff) |
util/hash_table: Rework the API to know about hashing
Previously, the hash_table API required the user to do all of the hashing
of keys as it passed them in. Since the hashing function is intrinsically
tied to the comparison function, it makes sense for the hash table to know
about it. Also, it makes for a somewhat clumsy API as the user is
constantly calling hashing functions many of which have long names. This
is especially bad when the standard call looks something like
_mesa_hash_table_insert(ht, _mesa_pointer_hash(key), key, data);
In the above case, there is no reason why the hash table shouldn't do the
hashing for you. We leave the option for you to do your own hashing if
it's more efficient, but it's no longer needed. Also, if you do do your
own hashing, the hash table will assert that your hash matches what it
expects out of the hashing function. This should make it harder to mess up
your hashing.
v2: change to call the old entrypoint "pre_hashed" rather than
"with_hash", like cworth's equivalent change upstream (change by
anholt, acked-in-general by Jason).
Signed-off-by: Jason Ekstrand <[email protected]>
Signed-off-by: Eric Anholt <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/util/tests/hash_table/replacement.c')
-rw-r--r-- | src/util/tests/hash_table/replacement.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/util/tests/hash_table/replacement.c b/src/util/tests/hash_table/replacement.c index 387cfc0fd94..01ede685826 100644 --- a/src/util/tests/hash_table/replacement.c +++ b/src/util/tests/hash_table/replacement.c @@ -36,24 +36,23 @@ main(int argc, char **argv) struct hash_table *ht; char *str1 = strdup("test1"); char *str2 = strdup("test1"); - uint32_t hash_str1 = _mesa_hash_string(str1); - uint32_t hash_str2 = _mesa_hash_string(str2); struct hash_entry *entry; assert(str1 != str2); - ht = _mesa_hash_table_create(NULL, _mesa_key_string_equal); + ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, + _mesa_key_string_equal); - _mesa_hash_table_insert(ht, hash_str1, str1, str1); - _mesa_hash_table_insert(ht, hash_str2, str2, str2); + _mesa_hash_table_insert(ht, str1, str1); + _mesa_hash_table_insert(ht, str2, str2); - entry = _mesa_hash_table_search(ht, hash_str1, str1); + entry = _mesa_hash_table_search(ht, str1); assert(entry); assert(entry->data == str2); _mesa_hash_table_remove(ht, entry); - entry = _mesa_hash_table_search(ht, hash_str1, str1); + entry = _mesa_hash_table_search(ht, str1); assert(!entry); _mesa_hash_table_destroy(ht, NULL); |