CountingBloomFilter Class

public closed class CountingBloomFilter

No documentation is available.

Methods

NameDescription
CreateAdler32(CountingBloomFilterSize)
CreateCrc32(CountingBloomFilterSize)
CreateCrc64(CountingBloomFilterSize)
CreateXXHash128(CountingBloomFilterSize)
CreateXXHash3(CountingBloomFilterSize)
CreateXXHash32(CountingBloomFilterSize)
CreateXXHash64(CountingBloomFilterSize)
Load(Stream)Creates a counting filter from a snapshot written by CountingBloomFilter.Save.
Load<TFilter>(Stream)Creates a counting filter of a given type from a snapshot written by CountingBloomFilter.Save.
LoadAsync(Stream, CancellationToken)Creates a counting filter from a snapshot written by CountingBloomFilter.Save or CountingBloomFilter.SaveAsync.
LoadAsync<TFilter>(Stream, CancellationToken)Creates a counting filter of a given type from a snapshot written by CountingBloomFilter.Save or CountingBloomFilter.SaveAsync.
Save(Stream)Writes a snapshot of the filter to a stream: its hash algorithm, its size and its counters.
SaveAsync(Stream, CancellationToken)Writes a snapshot of the filter to a stream: its hash algorithm, its size and its counters.

CreateAdler32(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterAdler32 CreateAdler32(CountingBloomFilterSize size)

No documentation is available.

CreateCrc32(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterCrc32 CreateCrc32(CountingBloomFilterSize size)

No documentation is available.

CreateCrc64(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterCrc64 CreateCrc64(CountingBloomFilterSize size)

No documentation is available.

CreateXXHash128(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterXXHash128 CreateXXHash128(CountingBloomFilterSize size)

No documentation is available.

CreateXXHash3(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterXXHash3 CreateXXHash3(CountingBloomFilterSize size)

No documentation is available.

CreateXXHash32(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterXXHash32 CreateXXHash32(CountingBloomFilterSize size)

No documentation is available.

CreateXXHash64(CountingBloomFilterSize)

BloomFilter.g.cs
public static CountingBloomFilterXXHash64 CreateXXHash64(CountingBloomFilterSize size)

No documentation is available.

Load overloads

Creates a counting filter from a snapshot written by CountingBloomFilter.Save.

public static CountingBloomFilter Load(Stream stream)
Parameters
stream Stream
The stream to read the snapshot from. It is left positioned after the snapshot.
Returns

CountingBloomFilter A new filter of the hash algorithm, size and content of the snapshot, such as a CountingBloomFilterXXHash128.

Exceptions
InvalidDataException
The data is not a Bloom filter snapshot, is truncated or corrupted, uses an unsupported version, contains a Bloom filter that is not a counting one, or was written on a machine with another byte order.
Remarks

The header is validated before the filter is allocated. When the stream is seekable, its length is also checked against the size of the filter first. The snapshot ends with a checksum, verified once it is read.

Load<TFilter>(Stream)

CountingBloomFilter.Snapshot.cs

Creates a counting filter of a given type from a snapshot written by CountingBloomFilter.Save.

public static TFilter Load<TFilter>(Stream stream) where TFilter : CountingBloomFilter
Type parameters
TFilter
The type of the filter, such as CountingBloomFilterXXHash128.
Parameters
stream Stream
The stream to read the snapshot from. It is left positioned after the snapshot.
Returns

TFilter A new filter of the size and content of the snapshot.

Exceptions
InvalidDataException
The snapshot contains a filter of another type, or is not valid (see CountingBloomFilter.Load).

LoadAsync overloads

LoadAsync(Stream, CancellationToken)

CountingBloomFilter.Snapshot.cs

Creates a counting filter from a snapshot written by CountingBloomFilter.Save or CountingBloomFilter.SaveAsync.

public static Task<CountingBloomFilter> LoadAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
stream Stream
The stream to read the snapshot from. It is left positioned after the snapshot.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<CountingBloomFilter> A new filter of the hash algorithm, size and content of the snapshot.

Exceptions
InvalidDataException
The snapshot is not valid (see CountingBloomFilter.Load).

LoadAsync<TFilter>(Stream, CancellationToken)

CountingBloomFilter.Snapshot.cs

Creates a counting filter of a given type from a snapshot written by CountingBloomFilter.Save or CountingBloomFilter.SaveAsync.

public static Task<TFilter> LoadAsync<TFilter>(Stream stream, CancellationToken cancellationToken = default) where TFilter : CountingBloomFilter
Type parameters
TFilter
The type of the filter, such as CountingBloomFilterXXHash128.
Parameters
stream Stream
The stream to read the snapshot from. It is left positioned after the snapshot.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<TFilter> A new filter of the size and content of the snapshot.

Exceptions
InvalidDataException
The snapshot contains a filter of another type, or is not valid (see CountingBloomFilter.Load).

Writes a snapshot of the filter to a stream: its hash algorithm, its size and its counters.

public void Save(Stream stream)

Parameters

stream Stream
The stream to write the snapshot to.

Remarks

The counters are copied through a small buffer, so saving a large filter does not allocate a second copy of it. Saturated counters are saved as they are, and stay saturated once loaded.

Stop adding and removing values while the snapshot is written. Each counter is read atomically, but the counters of a value updated during the write may be saved partially updated, so the restored filter may count it wrongly or report it as absent.

Keys are hashed from their in-memory bytes, so the snapshot records the byte order of the machine, and CountingBloomFilter.Load rejects a snapshot written on a machine with another byte order.

Example

var filter = CountingBloomFilter.CreateXXHash128(CountingBloomFilterSize.CreateOptimalSize(expectedItemCount: 1000, falsePositiveProbability: 0.01));
filter.Add("alice@example.com");
filter.Add("alice@example.com");

using var stream = new MemoryStream();
await filter.SaveAsync(stream);

stream.Position = 0;
var restored = await CountingBloomFilter.LoadAsync<CountingBloomFilterXXHash128>(stream);

Assert.Equal(2, restored.GetEstimatedCount("alice@example.com"));

SaveAsync(Stream, CancellationToken)

CountingBloomFilter.Snapshot.cs

Writes a snapshot of the filter to a stream: its hash algorithm, its size and its counters.

public Task SaveAsync(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream
The stream to write the snapshot to.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

Task A task that completes when the snapshot is written.

Remarks

See CountingBloomFilter.Save. Stop adding and removing values until the task completes.