3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

Add a remark to the BloomFilter javadocs about when you would want to use full-match filters.

This commit is contained in:
Mike Hearn 2013-07-30 16:05:04 +02:00
parent 41d2a8c62d
commit c2cff6df41

View File

@ -17,12 +17,13 @@
package com.google.bitcoin.core;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import static com.google.common.base.Preconditions.checkArgument;
/**
* <p>A Bloom filter is a probabilistic data structure which can be sent to another client so that it can avoid
* sending us transactions that aren't relevant to our set of keys. This allows for significantly more efficient
@ -233,29 +234,35 @@ public class BloomFilter extends Message {
}
/**
* Sets this filter to match all objects
* Sets this filter to match all objects. A Bloom filter which matches everything may seem pointless, however,
* it is useful in order to reduce steady state bandwidth usage when you want full blocks. Instead of receiving
* all transaction data twice, you will receive the vast majority of all transactions just once, at broadcast time.
* Solved blocks will then be send just as Merkle trees of tx hashes, meaning a constant 32 bytes of data for each
* transaction instead of 100-300 bytes as per usual.
*/
public void setMatchAll() {
data = new byte[] {(byte) 0xff};
}
/**
* Copies filter into this.
* filter must have the same size, hash function count and nTweak or an exception will be thrown.
* Copies filter into this. Filter must have the same size, hash function count and nTweak or an
* IllegalArgumentException will be thrown.
*/
public void merge(BloomFilter filter) {
if (!this.matchesAll() && !filter.matchesAll()) {
Preconditions.checkArgument(filter.data.length == this.data.length &&
filter.hashFuncs == this.hashFuncs &&
filter.nTweak == this.nTweak);
checkArgument(filter.data.length == this.data.length &&
filter.hashFuncs == this.hashFuncs &&
filter.nTweak == this.nTweak);
for (int i = 0; i < data.length; i++)
this.data[i] |= filter.data[i];
} else
} else {
this.data = new byte[] {(byte) 0xff};
}
}
/**
* Returns true if this filter will match anything
* Returns true if this filter will match anything. See {@link com.google.bitcoin.core.BloomFilter#setMatchAll()}
* for when this can be a useful thing to do.
*/
public boolean matchesAll() {
for (byte b : data)