summaryrefslogtreecommitdiff
path: root/tests/delete_and_lookup.c
AgeCommit message (Collapse)AuthorFilesLines
2013-10-25Teach the hash table itself to know its own hash functionCarl Worth1-12/+11
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-25Add new convenience function 'remove' (renaming former to 'remove_entry')Carl Worth1-2/+12
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)
2009-11-23Fix valgrind complaints, including leaking the table data!Eric Anholt1-1/+1
2009-11-23API change: pass the hash value in to search/lookup.Eric Anholt1-10/+12
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 a new test for removal of keys from the ht, and fix up API naming.Eric Anholt1-0/+73