summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2019-03-20Install the libs.HEADmasterEric Anholt1-0/+2
I expect people to generally want static libs, but if a shared build is done, it's not really useful without installing.
2019-03-20meson: Expose libs as dependencies.Eric Anholt1-0/+10
This will let them get used as a meson subproject.
2018-03-16Use set_foreach instead of rolling our own.Thomas Helland1-9/+3
This follows the same pattern as in the hash_table. (taken from Mesa commit 03e37ec6d720bb5d416e98d6f6d9663086939e4d and extended to the other loop as well, by anholt)
2018-03-16Add missing set_foreach().Eric Anholt1-0/+10
This was in the Mesa implementation but not upstream.
2017-12-01Add asserts that the user doesn't try to add the empty or deleted values.Eric Anholt2-0/+16
2017-12-01Add a meson build system.Eric Anholt1-0/+94
2017-12-01Add an editorconfig file for our style.Eric Anholt1-0/+14
2016-03-02Add a testcase for the replacement bug fixed in the previous commit.Eric Anholt9-0/+197
2016-03-02Do a full search when adding new itemsJason Ekstrand3-19/+47
Previously, the hash_table_insert or set_add functions 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. v2: Fold in Connor Abbot's fix to not check keys in deleted entries. v3: Propagate this change to int-set, too (change by anholt). Reviewed-by: Eric Anholt <eric@anholt.net>
2016-03-02Fix replacement of deleted entries in the int set.Eric Anholt4-1/+64
Caught while writing tests for the next bugfix.
2016-03-02Add a testcase for a bug that was introduced in Mesa.Eric Anholt6-0/+132
This tree doesn't have the bug, but I'd like to bring the change that was buggy over.
2016-03-02Fix compiler warning in delete_management.Eric Anholt1-1/+0
2014-11-25Make helpers for creating hash tables and sets of strings.Eric Anholt10-9/+19
This fixes warnings when building the testsuite, due to char * vs void * in prototypes.
2014-11-25Add a variant of the hash funciton for arbitrary data.Eric Anholt2-0/+16
Mesa was using this for hashing various key structures.
2014-11-25Note that the hash used is actually FNV-1a.Timothy Arceri1-2/+2
FNV-1 has the XOR and the MUL in the opposite order.
2013-10-25Cleanup implementation of set to prefer "set" over "hash table" or "ht"cworth-with-warningsCarl Worth1-91/+93
The interface was already using "set" for the primary identifier, but the implementation still had "ht" as the identifier and various uses of "hash table" or "table" in the documentation comments where "set" makes more sense. v2: Rebase on change in previous commit's v2 (by anholt)
2013-10-25Teach the hash table itself to know its own hash functionCarl Worth21-135/+218
Here, we change 'create' to accept the hash function. This simplifies the interface for 'insert', 'search', 'contains', and 'remove' which no longer need to pass a hash value, making them more convenient to use. To avoid any reduction in performance, the previous interfaces for 'insert' and 'search' are still available as 'insert_pre_hashed' and 'search_pre_hashed'. This avoids redundant hashing in cases where the caller already has a hash value. (The common case is to has once before 'search_pre_hashed' and then reuse that value for 'insert_pre_hashed'.) The implementation takes advantage of the 'insert_pre_hashed' version when performing hash_rehash as part of resizing the table. Note that 'remove' does not need a pre_hashed variant since 'remove' is already a convenience function on top of 'remove_entry', and 'remove_entry' already has access to the hash value inside of the entry. Similarly, 'contains' does not need a pre_hashed variant since it is a convnience function on top of 'search' which already has a 'search_pre_hashed' variant. In this commit, the tests are modified such that roughly half of the previous callers of 'search' and 'insert' are changed to the new interface and the other half remain with the old interface (now named 'search_pre_hashed' and 'insert_pre_hashed'). v2: Make the new method call style consistent with the key equality method (change by anholt).
2013-10-25Fix out-of-tree build.Eric Anholt3-3/+3
2013-10-25Add set_contains and int_set_contains functions.Carl Worth14-4/+60
These are convenience functions on top of set_search and int_set_search. With a set, containment is often the most important notion of interest, and it helps to be able to query this without needing to declare a local struct set_entry*. v2: Whitespace consistency (changes by anholt)
2013-10-25Add new convenience function 'remove' (renaming former to 'remove_entry')Carl Worth19-30/+117
The new 'remove' function provides a parallel interface to that of search, (removing an entry matching the provided data). The former remove function (which accepts a pointer to a known entry) is renamed to 'remove_entry'. This new 'remove' is a simple convenience function which calls 'search' and then 'remove_entry'. As can be seen in the updates to the test suite, there are cases where the caller was already doing exactly that, so the new interface simplifies such uses. v2: Whitespace consistency change (by anholt)
2013-10-25Add a new int-set structure for a set of integersCarl Worth15-1/+918
Much like the motivation for the original set.c, this int-set.c code is not difficult, but it makes sense to do this up-front in the original hash_table module (with testing) rather than expecting users to repeat this work.
2013-10-25Add multiple-inclusion guards for header files.Carl Worth2-0/+10
As is standard practice.
2013-10-25Standardize language for license blurbs.Carl Worth3-21/+24
This extends the language from the source files into the Makefiles as well. The most significant change is from "ADAM JACKSON" to "THE AUTHORS OR COPYRIGHT HOLDERS". While I'm sure that Adam would appreciate any reduction in liability, the intent of this language is to disclaim liability for the actual authors and copyright holders. (I don't know that Adam actually has any copyright interest in this implementation, but if he does, he's still covered by the wider language.)
2013-10-25Update .gitignore filesCarl Worth3-0/+6
Just enough to keep "git status" clean after running "make check".
2013-10-25Whitespace cleanup for header files.Carl Worth2-23/+39
It's so much easier to find function names in the header file when they are in column 0 where they belong.
2012-11-06Fix the prototype of fnv1_hash_string().Eric Anholt2-6/+6
2012-11-06Add a note why hash_table_random_entry() may be of use.Eric Anholt1-0/+8
2012-11-06Clarify the loop end conditions.Eric Anholt1-6/+7
Based on a comment by Chad Versace.
2012-11-06Make a few function args const.Eric Anholt2-6/+6
Noted by Brian Paul in review for Mesa.
2012-11-06Make the deleted_key variables static const.Eric Anholt2-4/+4
I think I may have made them public thinking of reaching over for them in testcases for poking at deleted key behavior, but this makes more sense. Noted by Chad Versace.
2012-11-06Add a test case for handling of collisions.Eric Anholt2-0/+82
2012-10-18Add C++ guards, in case you're importing this in some disaster C/C++ mix.Eric Anholt2-4/+9
2012-10-18Add a hash_table_foreach() macro.Eric Anholt2-6/+12
I kept rewriting this in an user of this code.
2011-08-18Add a set implementation derived from the hash_table implementation.Eric Anholt17-7/+1062
While it was easy to produce, it's easier to do it once and maintain it than leave this up to every possible user. Plus, it means it gets testing.
2011-08-18Make hash_table_remove(ht, NULL) do nothing instead of segfault.Eric Anholt4-0/+51
2011-08-18Add defined behavior for inserts with matching keys, and a test.Eric Anholt5-2/+88
2011-08-18Improve double hashing.Eric Anholt1-6/+2
Because of the double_hash == 0 check, the step size of 1 would have twice the frequency of any other. With the table size being prime numbers, any integer is co-prime with the table size, so any nonzero step number will end up hitting every element of the hash table. Based on a patch by Andrea Canciani to the X Server.
2010-01-19Clean up the hash_table_destroy implementation.Eric Anholt1-4/+2
2009-11-25Fix the double hashing to be double hashing instead of linear probing.Eric Anholt1-2/+13
2009-11-25fnv1a: use the correct offset basis so that 0-filled buffers hash by length.Eric Anholt1-1/+1
Reported by: Chris Wilson
2009-11-24Prevent ht->entries from doubling when rehashing.Eric Anholt3-0/+3
2009-11-24Fix destroy_callback test.Eric Anholt1-1/+3
2009-11-23Fix flipped order of operations in fnv hash.Eric Anholt1-1/+1
2009-11-23Fix valgrind complaints, including leaking the table data!Eric Anholt6-6/+7
2009-11-23Add deleted entry management by rehashing on insert when appropriate.Eric Anholt3-8/+32
2009-11-23Add a testcase for the upcoming deletion management code.Eric Anholt6-5/+107
2009-11-23API change: pass the hash value in to search/lookup.Eric Anholt7-58/+42
This avoids re-hashing the key for the common use case of searching for the key's presence, then creating the entry if it isn't.
2009-11-23Add an interface for choosing a random hash table entry with a predicate.Eric Anholt5-0/+132
2009-11-23destroy_callback: New test for the destroy hashtable callback.Eric Anholt2-0/+66
2009-11-23Fix the insert_many test: implement resize, and fix operator typos.Eric Anholt1-7/+36