new Bloom(size, n, tweak, update)
Bloom Filter
Parameters:
Name | Type | Description |
---|---|---|
size |
Number | Filter size in bits. |
n |
Number | Number of hash functions. |
tweak |
Number | Seed value. |
update |
Number | String | Update type. |
Properties:
Name | Type | Description |
---|---|---|
filter |
Buffer | |
size |
Number | |
n |
Number | |
tweak |
Number | |
update |
Number | Update flag (see Bloom.flags). |
- Source:
Members
(static) flags :Number
Bloom filter update flags.
Type:
- Number
Properties:
Name | Type | Description |
---|---|---|
NONE |
Number | Never update the filter with outpoints. |
ALL |
Number | Always update the filter with outpoints. |
PUBKEY_ONLY |
Number | Only update the filter with outpoints if it is "asymmetric" in terms of addresses (pubkey/multisig). |
- Default Value:
{"NONE":0,"ALL":1,"PUBKEY_ONLY":2}
- Source:
(static, constant) flagsByVal :RevMap
Bloom filter update flags by value.
Type:
- Source:
(static, constant) MAX_BLOOM_FILTER_SIZE :Number
Max bloom filter size.
Type:
- Number
- Default Value:
- 36000
- Source:
(static, constant) MAX_HASH_FUNCS :Number
Max number of hash functions.
Type:
- Number
- Default Value:
- 50
- Source:
Methods
(static) fromOptions(size, n, tweak, update) → {Bloom}
Instantiate bloom filter from options.
Parameters:
Name | Type | Description |
---|---|---|
size |
Number | Filter size in bits. |
n |
Number | Number of hash functions. |
tweak |
Number | Seed value. |
update |
Number | String | Update type. |
- Source:
Returns:
- Type
- Bloom
(static) fromRate(items, rate, update) → {Boolean}
Create a filter from a false positive rate.
Parameters:
Name | Type | Description |
---|---|---|
items |
Number | Expected number of items. |
rate |
Number | False positive rate (0.0-1.0). |
update |
Number | String |
- Source:
Returns:
- Type
- Boolean
Example
Bloom.fromRate(800000, 0.0001, 'none');
(static) fromRaw(data, encnullable) → {Bloom}
Instantiate bloom filter from serialized data.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
- Source:
Returns:
- Type
- Bloom
(static) fromReader(br) → {Bloom}
Instantiate bloom filter from buffer reader.
Parameters:
Name | Type | Description |
---|---|---|
br |
BufferReader |
- Source:
Returns:
- Type
- Bloom
add(val, encnullable)
Add data to the filter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
val |
Buffer | String | ||
enc |
String |
<nullable> |
Can be any of the Buffer object's encodings. |
- Source:
added(val, encnullable) → {Boolean}
Test whether data is present in the filter and potentially add data.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
val |
Buffer | String | ||
enc |
String |
<nullable> |
Can be any of the Buffer object's encodings. |
- Source:
Returns:
Whether data was added.
- Type
- Boolean
(private) fromOptions(size, n, tweak, update) → {Bloom}
Inject properties from options.
Parameters:
Name | Type | Description |
---|---|---|
size |
Number | Filter size in bits. |
n |
Number | Number of hash functions. |
tweak |
Number | Seed value. |
update |
Number | String | Update type. |
- Source:
Returns:
- Type
- Bloom
(private) fromRaw(data)
Inject properties from serialized data.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer |
- Source:
(private) fromReader(br)
Inject properties from buffer reader.
Parameters:
Name | Type | Description |
---|---|---|
br |
BufferReader |
- Source:
getSize() → {Number}
Get serialization size.
- Source:
Returns:
- Type
- Number
hash(val, n) → {Number}
Perform the mumur3 hash on data.
Parameters:
Name | Type | Description |
---|---|---|
val |
Buffer | |
n |
Number |
- Source:
Returns:
- Type
- Number
isWithinConstraints() → {Boolean}
Ensure the filter is within the size limits.
- Source:
Returns:
- Type
- Boolean
reset()
Reset the filter.
- Source:
test(val, encnullable) → {Boolean}
Test whether data is present in the filter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
val |
Buffer | String | ||
enc |
String |
<nullable> |
Can be any of the Buffer object's encodings. |
- Source:
Returns:
- Type
- Boolean
toRaw() → {Buffer}
Serialize bloom filter.
- Source:
Returns:
- Type
- Buffer
toWriter(bw)
Write filter to buffer writer.
Parameters:
Name | Type | Description |
---|---|---|
bw |
BufferWriter |
- Source: