mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-04 17:52:25 +01:00
More efficient bitsliced rolling Bloom filter
This patch changes the implementation from one that stores 16 2-bit integers in one uint32_t's, to one that stores the first bit of 64 2-bit integers in one uint64_t and the second bit in another. This allows for 450x faster refreshing and 2.2x faster average speed.
This commit is contained in:
13
src/bloom.h
13
src/bloom.h
@@ -135,20 +135,9 @@ private:
|
||||
int nEntriesPerGeneration;
|
||||
int nEntriesThisGeneration;
|
||||
int nGeneration;
|
||||
std::vector<uint32_t> data;
|
||||
std::vector<uint64_t> data;
|
||||
unsigned int nTweak;
|
||||
int nHashFuncs;
|
||||
|
||||
unsigned int Hash(unsigned int nHashNum, const std::vector<unsigned char>& vDataToHash) const;
|
||||
|
||||
inline int get(uint32_t position) const {
|
||||
return (data[(position >> 4) % data.size()] >> (2 * (position & 0xF))) & 0x3;
|
||||
}
|
||||
|
||||
inline void put(uint32_t position, uint32_t val) {
|
||||
uint32_t& cell = data[(position >> 4) % data.size()];
|
||||
cell = (cell & ~(((uint32_t)3) << (2 * (position & 0xF)))) | (val << (2 * (position & 0xF)));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BITCOIN_BLOOM_H
|
||||
|
||||
Reference in New Issue
Block a user