aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/hash_table.c
Commit message (Collapse)AuthorAgeFilesLines
* util/hash_table: Fix hashing in clears on 32-bitTomeu Vizoso2019-08-081-2/+12
| | | | | | | | | | | | | | | | | | | Some hash functions (eg. key_u64_hash) will attempt to dereference the key, causing an invalid access when passed DELETED_KEY_VALUE (0x1) or FREED_KEY_VALUE (0x0). When in 32-bit arch a 64-bit key value doesn't fit into a pointer, so hash_table_u64 internally use a pointer to a struct containing the 64-bit key value. Fix _mesa_hash_table_u64_clear() to handle the 32-bit case by creating a temporary hash_key_u64 to pass to the hash function. Signed-off-by: Tomeu Vizoso <[email protected]> Suggested-by: Caio Marcelo de Oliveira Filho <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Cc: Samuel Pitoiset <[email protected]> Cc: Nicolai Hähnle <[email protected]>
* i965: Fix INTEL_DEBUG=batCaio Marcelo de Oliveira Filho2019-06-121-2/+13
| | | | | | | | | | | | | Use hash_table_u64 instead of hash_table directly, since the former will also handle the special keys (deleted and freed) and allow use the whole u64 space. Fixes crash in INTEL_DEBUG=bat when using a key with value 0 -- the current value for a freed key. Fixes: b38dab101ca "util/hash_table: Assert that keys are not reserved pointers" Reviewed-by: Lionel Landwerlin <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* util/hash_table: Properly handle the NULL key in hash_table_u64Caio Marcelo de Oliveira Filho2019-06-121-5/+36
| | | | | | | | | | The hash_table_u64 should support any uint64_t as input. It does special handling for the "deleted" key, storing the data in the table itself; do the same for the "freed" key. Fixes: b38dab101ca "util/hash_table: Assert that keys are not reserved pointers" Reviewed-by: Lionel Landwerlin <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* util/hash_table: Assert that keys are not reserved pointersJason Ekstrand2019-06-061-1/+9
| | | | | | | | | | | If we insert a NULL key, it will appear to succeed but will mess up entry counting. Similar errors can occur if someone accidentally inserts the deleted key. The later is highly unlikely but technically possible so we should guard against it too. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* util/hash_table: Use fast modulo computationConnor Abbott2019-05-311-37/+50
| | | | | | | | While we're here, copy the size table from set.c to get rid of hard tabs in the hash_table.c version. Reviewed-by: Eric Anholt <[email protected]> Acked-by: Jason Ekstrand <[email protected]>
* util/hash_table: Add specialized resizing add functionConnor Abbott2019-05-311-1/+27
| | | | | | | To keep it in sync with the set implementation. Reviewed-by: Eric Anholt <[email protected]> Acked-by: Jason Ekstrand <[email protected]>
* util/hash_table: Pull out loop-invariant computationsConnor Abbott2019-05-311-14/+13
| | | | | | | | | To keep the set and hash table in sync. Note that some of this had already been done for hash tables, in particular pulling out the hash % ht->size computation. Reviewed-by: Eric Anholt <[email protected]> Acked-by: Jason Ekstrand <[email protected]>
* util: Helper to create sets and hashes with pointer keysCaio Marcelo de Oliveira Filho2019-01-141-0/+10
| | | | | | | These combinations are common enough and deserve a shortcut. Reviewed-by: Jason Ekstrand <[email protected]> Acked-by: Eric Engestrom <[email protected]>
* util/hash_table: Add _mesa_hash_table_init functionIan Romanick2018-12-161-13/+26
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* util: use C99 declaration in the for-loop hash_table_foreach() macroEric Engestrom2018-10-251-3/+1
| | | | | Signed-off-by: Eric Engestrom <[email protected]> Reviewed-by: Timothy Arceri <[email protected]>
* util/hash_table: add helper to remove entry by keyCaio Marcelo de Oliveira Filho2018-07-131-0/+9
| | | | | | And the corresponding test case. Reviewed-by: Eric Anholt <[email protected]>
* util: Implement a hash table cloning functionThomas Helland2018-03-141-0/+22
| | | | | | | V2: Don't rzalloc; we are about to rewrite the whole thing (Vladislav) Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
* util: hashtable: make hashing prototypes matchLionel Landwerlin2017-10-301-1/+2
| | | | | | | | | It seems nobody's using the string hashing function. If you try to pass it directly to the hashtable creation function, you'll get compiler warning for non matching prototypes. Let's make them match. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* util: fix warning/error on 32bit buildTapani Pälli2017-07-251-2/+2
| | | | | | | | | Add uintptr_t cast to fix 'cast to pointer from integer of different size' warning on 32bit build (build error on Android M). Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Michel Dänzer <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]>
* mesa/util: add a hash table wrapper which support 64-bit keysSamuel Pitoiset2017-06-141-0/+147
| | | | | | | | | Needed for bindless handles which are represented using 64-bit unsigned integers. All hash table implementations should be uniformized later on. Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Nicolai Hähnle <[email protected]>
* util: add assert that key cannot be NULL on insertionTapani Pälli2016-08-221-0/+2
| | | | | | Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* util/hash_table: add _mesa_hash_table_clear (v4)Nicolai Hähnle2016-02-031-0/+26
| | | | | | v4: coding style change (Matt Turner) Reviewed-by: Ian Romanick <[email protected]> (v3)
* util/hash_table: don't compare deleted entriesConnor Abbott2016-02-021-1/+2
| | | | | | | | | | | The equivalent of the last patch for the hash table. I'm not aware of any issues this fixes. v2: - use entry_is_deleted (Timothy) Reviewed-by: Timothy Arceri <[email protected]> Signed-off-by: Connor Abbott <[email protected]>
* util/hash_table: Do a full search when adding new itemsJason Ekstrand2015-02-071-7/+16
| | | | | | | | | | | | Previously, the hash_table_insert function would bail early if it found a deleted slot that it could re-use. However, this is a problem if the key being inserted is already in the hash table but further down the list. If this happens, the element ends up getting inserted in the hash table twice. This commit makes it so that we walk over all of the possible entries for the given key and then, if we don't find the key, place it in the available free entry we found. Reviewed-by: Eric Anholt <[email protected]>
* mesa: Fix some signed-unsigned comparison warningsJan Vesely2015-01-211-1/+1
| | | | | | | | v2: s/unsigned int/unsigned/ in prog_optimize.c Signed-off-by: Jan Vesely <[email protected]> Reviewed-by: David Heidelberg <[email protected]> Reviewed-by: Jose Fonseca <[email protected]>
* hash_table: Rename insert_with_hash to insert_pre_hashedJason Ekstrand2015-01-151-2/+2
| | | | | | | We already have search_pre_hashed. This makes the APIs match better. Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* util/hash_table: Pull the details of the FNV-1a into helpersJason Ekstrand2015-01-151-13/+4
| | | | | | | This way the basics of the FNV-1a hash can be reused to easily create other hashing functions. Reviewed-by: Eric Anholt <[email protected]>
* hash_table: Fix compiler warnings from the renaming.Eric Anholt2014-12-141-2/+2
| | | | | Not sure how we both missed this. None of the callers were using the return value, though.
* util/hash_table: Rework the API to know about hashingJason Ekstrand2014-12-141-20/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | 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]>
* util: update hash type commentsTimothy Arceri2014-11-261-5/+5
| | | | | Signed-off-by: Timothy Arceri <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* util: Gather some common macrosJason Ekstrand2014-08-041-1/+1
| | | | | | | | | | This gathers macros that have been included across components into util so that the include chain can be more vertical. In particular, this makes util stand on its own without any dependence whatsoever on the rest of mesa. Signed-off-by: "Jason Ekstrand" <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
* util: Move the open-addressing linear-probing hash_table to src/util.Kenneth Graunke2014-08-041-0/+440
This hash table is used in core Mesa, the GLSL compiler, and the i965 driver, which makes it a good candidate for the new src/util module. It's much faster than program/hash_table.[ch] (see commit 6991c2922f5 for data), and José's u_hash_table.c has a comment saying Gallium should probably consider switching to a linear probing hash table at some point. So this seems like the best candidate for a shared data structure. Signed-off-by: Kenneth Graunke <[email protected]> v2 (Jason Ekstrand): Pick up another hash_table use and patch up scons Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Marek Olšák <[email protected]>