mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 03:35:52 +00:00
Make BloomFilter support match-all filters better
This commit is contained in:
parent
2808b062d7
commit
d88d421de6
@ -232,16 +232,36 @@ public class BloomFilter extends Message {
|
|||||||
Utils.setBitLE(data, hash(i, object));
|
Utils.setBitLE(data, hash(i, object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets this filter to match all objects
|
||||||
|
*/
|
||||||
|
public void setMatchAll() {
|
||||||
|
data = new byte[] {(byte) 0xff};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies filter into this.
|
* Copies filter into this.
|
||||||
* filter must have the same size, hash function count and nTweak or an exception will be thrown.
|
* filter must have the same size, hash function count and nTweak or an exception will be thrown.
|
||||||
*/
|
*/
|
||||||
public void merge(BloomFilter filter) {
|
public void merge(BloomFilter filter) {
|
||||||
|
if (!this.matchesAll() && !filter.matchesAll()) {
|
||||||
Preconditions.checkArgument(filter.data.length == this.data.length &&
|
Preconditions.checkArgument(filter.data.length == this.data.length &&
|
||||||
filter.hashFuncs == this.hashFuncs &&
|
filter.hashFuncs == this.hashFuncs &&
|
||||||
filter.nTweak == this.nTweak);
|
filter.nTweak == this.nTweak);
|
||||||
for (int i = 0; i < data.length; i++)
|
for (int i = 0; i < data.length; i++)
|
||||||
this.data[i] |= filter.data[i];
|
this.data[i] |= filter.data[i];
|
||||||
|
} else
|
||||||
|
this.data = new byte[] {(byte) 0xff};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this filter will match anything
|
||||||
|
*/
|
||||||
|
public boolean matchesAll() {
|
||||||
|
for (byte b : data)
|
||||||
|
if (b != (byte) 0xff)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user