summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
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
2009-11-23New test for expanding the hash table and not losing entries.Eric Anholt3-0/+81
2009-11-23Add a new test for removal of keys from the ht, and fix up API naming.Eric Anholt4-2/+76
2009-11-23Fix segfault in insert_and_lookup test.Eric Anholt1-0/+1
2009-11-23Add testing infrastructure.Eric Anholt8-3/+224
2009-11-23Remove AM_MAINTAINER_MODE stuff.Eric Anholt2-2/+1
While it was cargo-culted from many other projects, allowing people to lose the Makefile regeneration rules is a recipe for disaster. autotools is apparently discouraging the presence of AM_MAINTAINER_MODE, in a shocking bout of sanity.
2009-11-23Initial import of hash_table.Eric Anholt8-0/+497
This is entirely written by myself, with the exception of the hash_sizes[] contents which come from the hash_table implementation in nickle, which I decided to not use.