BloomFilter class

A space-efficient probabilistic set membership test.

Usage:

// Build a filter from local message IDs
final filter = BloomFilter.optimal(expectedItems: messages.length);
for (final msg in messages) {
  filter.add(msg.messageId);
}

// Send filter.toBytes() to peer...

// Peer uses it to filter outgoing messages:
if (!peerFilter.mightContain(msg.messageId)) {
  // Peer definitely doesn't have this message — send it
}

Constructors

BloomFilter.empty()
Creates an empty Bloom filter that accepts everything.
factory
BloomFilter.fromBytes(Uint8List data)
Deserializes a Bloom filter from bytes.
factory
BloomFilter.optimal({required int expectedItems, double falsePositiveRate = 0.01})
Creates an optimally-sized Bloom filter for expectedItems with the given falsePositiveRate.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this is an empty/passthrough filter.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sizeInBytes int
The size of this filter in bytes (just the bit array, not the header).
no setter

Methods

add(String item) → void
Adds an item to the filter.
mightContain(String item) bool
Tests whether an item might be in the filter.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBytes() Uint8List
Serializes the Bloom filter to bytes for transmission.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited