diff options
author | Jason Ekstrand <[email protected]> | 2015-01-15 09:31:18 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-01-15 13:21:27 -0800 |
commit | 153b8b35257fb5d68735b5e43e48b0cdb8b15170 (patch) | |
tree | 05db6c87edc7a57a0b7b3457a35448962b4c1c76 /src/util/set.h | |
parent | 4c99e3ae78ed3524d188f00b558f803a943aaa00 (diff) |
util/hash_set: Rework the API to know about hashing
Previously, the set 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 set 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_set_add(ht, _mesa_pointer_hash(key), key);
In the above case, there is no reason why the hash set 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 set will assert that your hash matches what it
expects out of the hashing function. This should make it harder to mess up
your hashing.
This is analygous to 94303a0750 where we did this for hash_table
Signed-off-by: Jason Ekstrand <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/util/set.h')
-rw-r--r-- | src/util/set.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/util/set.h b/src/util/set.h index 206d0c4d24f..9acd2c28c9f 100644 --- a/src/util/set.h +++ b/src/util/set.h @@ -43,6 +43,7 @@ struct set_entry { struct set { void *mem_ctx; struct set_entry *table; + uint32_t (*key_hash_function)(const void *key); bool (*key_equals_function)(const void *a, const void *b); uint32_t size; uint32_t rehash; @@ -54,6 +55,7 @@ struct set { struct set * _mesa_set_create(void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), bool (*key_equals_function)(const void *a, const void *b)); void @@ -61,11 +63,15 @@ _mesa_set_destroy(struct set *set, void (*delete_function)(struct set_entry *entry)); struct set_entry * -_mesa_set_add(struct set *set, uint32_t hash, const void *key); +_mesa_set_add(struct set *set, const void *key); +struct set_entry * +_mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key); struct set_entry * -_mesa_set_search(const struct set *set, uint32_t hash, - const void *key); +_mesa_set_search(const struct set *set, const void *key); +struct set_entry * +_mesa_set_search_pre_hashed(const struct set *set, uint32_t hash, + const void *key); void _mesa_set_remove(struct set *set, struct set_entry *entry); |