From a4bcff5ba36115495994e9f9ba66074471de76ab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 26 Oct 2012 03:24:03 +0200 Subject: journal: introduce entry array chain cache When traversing entry array chains for a bisection or for retrieving an item by index we previously always started at the beginning of the chain. Since we tend to look at the same chains repeatedly, let's cache where we have been the last time, and maybe we can skip ahead with this the next time. This turns most bisections and index lookups from O(log(n)*log(n)) into O(log(n)). More importantly however, we seek around on disk much less, which is good to reduce buffer cache and seek times on rotational disks. --- src/shared/hashmap.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/shared/hashmap.c') diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c index ef78070f4c..dcfbb67228 100644 --- a/src/shared/hashmap.c +++ b/src/shared/hashmap.c @@ -147,6 +147,25 @@ int trivial_compare_func(const void *a, const void *b) { return a < b ? -1 : (a > b ? 1 : 0); } +unsigned uint64_hash_func(const void *p) { + uint64_t u; + + assert_cc(sizeof(uint64_t) == 2*sizeof(unsigned)); + + u = *(const uint64_t*) p; + + return (unsigned) ((u >> 32) ^ u); +} + +int uint64_compare_func(const void *_a, const void *_b) { + uint64_t a, b; + + a = *(const uint64_t*) _a; + b = *(const uint64_t*) _b; + + return a < b ? -1 : (a > b ? 1 : 0); +} + Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) { bool b; Hashmap *h; -- cgit v1.2.3-54-g00ecf