diff options
author | Rob Kendrick (humdrum) <rob.kendrick@codethink.co.uk> | 2013-05-16 17:24:05 +0100 |
---|---|---|
committer | Rob Kendrick (humdrum) <rob.kendrick@codethink.co.uk> | 2013-05-16 17:24:05 +0100 |
commit | 0c45ed935d81d7df958604ae4df34fda7181fca8 (patch) | |
tree | eb6f8f4818aaf438939f3cbece459e201f56e129 /utils | |
parent | 7d60132816341e15a853f2f66f06d0755d0f2daa (diff) | |
download | netsurf-0c45ed935d81d7df958604ae4df34fda7181fca8.tar.gz netsurf-0c45ed935d81d7df958604ae4df34fda7181fca8.tar.bz2 |
Better bit and byte selection
Diffstat (limited to 'utils')
-rw-r--r-- | utils/bloom.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/utils/bloom.c b/utils/bloom.c index e6b9dcf92..1b07d6f1b 100644 --- a/utils/bloom.c +++ b/utils/bloom.c @@ -20,7 +20,6 @@ * Trivial bloom filter */ #include <stdlib.h> -#include <stdio.h> #include "utils/bloom.h" /** @@ -79,10 +78,11 @@ void bloom_insert_str(struct bloom_filter *b, const char *s, size_t z) void bloom_insert_hash(struct bloom_filter *b, uint32_t hash) { - int index = hash % b->size; - int bit = hash % 8; + unsigned int index = hash % (b->size << 3); + unsigned int byte_index = index >> 3; + unsigned int bit_index = index & 7; - b->filter[index] |= (1 << bit); + b->filter[byte_index] |= (1 << bit_index); b->items++; } @@ -94,10 +94,11 @@ bool bloom_search_str(struct bloom_filter *b, const char *s, size_t z) bool bloom_search_hash(struct bloom_filter *b, uint32_t hash) { - int index = hash % b->size; - int bit = hash % 8; + unsigned int index = hash % (b->size << 3); + unsigned int byte_index = index >> 3; + unsigned int bit_index = index & 7; - return (b->filter[index] & (1 << bit)) != 0; + return (b->filter[byte_index] & (1 << bit_index)) != 0; } uint32_t bloom_items(struct bloom_filter *b) |