summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2015-12-27 07:50:11 +0000
committered <ed@FreeBSD.org>2015-12-27 07:50:11 +0000
commitf846ec41eb13d12aef5eb8990a1f316a8462acb6 (patch)
treee48e71d6533d59f033b2f296db025e7b794896b4 /include
parent839ab24e1e9db5b4373711c6c51f1e62d56e8536 (diff)
downloadFreeBSD-src-f846ec41eb13d12aef5eb8990a1f316a8462acb6.zip
FreeBSD-src-f846ec41eb13d12aef5eb8990a1f316a8462acb6.tar.gz
Replace implementation of hsearch() by one that scales.
Traditionally the hcreate() function creates a hash table that uses chaining, using a fixed user-provided size. The problem with this approach is that this often either wastes memory (table too big) or yields bad performance (table too small). For applications it may not always be easy to estimate the right hash table size. A fixed number only increases performance compared to a linked list by a constant factor. This problem can be solved easily by dynamically resizing the hash table. If the size of the hash table is at least doubled, this has no negative on the running time complexity. If a dynamically sized hash table is used, we can also switch to using open addressing instead of chaining, which has the advantage of just using a single allocation for the entire table, instead of allocating many small objects. Finally, a problem with the existing implementation is that its deterministic algorithm for hashing makes it possible to come up with fixed patterns to trigger an excessive number of collisions. We can easily solve this by using FNV-1a as a hashing algorithm in combination with a randomly generated offset basis. Measurements have shown that this implementation is about 20-25% faster than the existing implementation (even if the existing implementation is given an excessive number of buckets). Though it allocates more memory through malloc() than the old implementation (between 4-8 pointers per used entry instead of 3), process memory use is similar to the old implementation as if the estimated size was underestimated by a factor 10. This is due to the fact that malloc() needs to perform less bookkeeping. Reviewed by: jilles, pfg Obtained from: https://github.com/NuxiNL/cloudlibc Differential Revision: https://reviews.freebsd.org/D4644
Diffstat (limited to 'include')
-rw-r--r--include/search.h5
1 files changed, 1 insertions, 4 deletions
diff --git a/include/search.h b/include/search.h
index 8ddf416..4c1f534 100644
--- a/include/search.h
+++ b/include/search.h
@@ -47,11 +47,8 @@ struct que_elem {
#endif
#if __BSD_VISIBLE
-struct _ENTRY;
struct hsearch_data {
- struct _ENTRY *table;
- size_t size;
- size_t filled;
+ struct __hsearch *__hsearch;
};
#endif
OpenPOWER on IntegriCloud