[Mesa-dev] [PATCH] util/hash_table: Rework the API to know about hashing
Kenneth Graunke
kenneth at whitecape.org
Tue Nov 25 00:58:38 PST 2014
On Monday, November 24, 2014 10:19:50 PM Jason Ekstrand wrote:
> 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 intrinsicly
> 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.
>
> Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
(CC'ing Eric to make sure he sees your patch - it's his code after all)
Yes, please - the new API looks much nicer to work with. This should be
especially nice in the compiler, where we have a lot of hash tables, and
aren't concerned with saving every last CPU cycle.
I like that there are still _with_hash variants, so you can still compute
the hash once and use it multiple times where that makes sense.
--Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141125/72c07afb/attachment.sig>
More information about the mesa-dev
mailing list