diff options
author | Matt Corallo <git@bluematt.me> | 2012-11-02 18:33:50 -0400 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2013-01-16 12:48:02 -0500 |
commit | b1f99bed6f0fbbe94e6a3161b49b3f225dec8374 (patch) | |
tree | ae47ef2b17af591fdcd3a07e1e957513a694304d /src/bloom.h | |
parent | 4c8fc1a5885634c3b463d5d44337d81cc5b1456b (diff) |
Add a nTweak to bloom filters to tweak the seed.
Diffstat (limited to 'src/bloom.h')
-rw-r--r-- | src/bloom.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/bloom.h b/src/bloom.h index 1a8a562dad..a59b1d99f5 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -33,6 +33,7 @@ class CBloomFilter private: std::vector<unsigned char> vData; unsigned int nHashFuncs; + unsigned int nTweak; unsigned int Hash(unsigned int nHashNum, const std::vector<unsigned char>& vDataToHash) const; @@ -41,7 +42,9 @@ public: // Note that if the given parameters will result in a filter outside the bounds of the protocol limits, // the filter created will be as close to the given parameters as possible within the protocol limits. // This will apply if nFPRate is very low or nElements is unreasonably high. - CBloomFilter(unsigned int nElements, double nFPRate); + // nTweak is a constant which is added to the seed value passed to the hash function + // It should generally always be a random value (and is largely only exposed for unit testing) + CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak); // Using a filter initialized with this results in undefined behavior // Should only be used for deserialization CBloomFilter() {} @@ -50,6 +53,7 @@ public: ( READWRITE(vData); READWRITE(nHashFuncs); + READWRITE(nTweak); ) void insert(const std::vector<unsigned char>& vKey); |