CountingBloomFilter Class
public closed class CountingBloomFilterNo documentation is available.
Methods
CreateAdler32(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterAdler32 CreateAdler32(CountingBloomFilterSize size)No documentation is available.
CreateCrc32(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterCrc32 CreateCrc32(CountingBloomFilterSize size)No documentation is available.
CreateCrc64(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterCrc64 CreateCrc64(CountingBloomFilterSize size)No documentation is available.
CreateXXHash128(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterXXHash128 CreateXXHash128(CountingBloomFilterSize size)No documentation is available.
CreateXXHash3(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterXXHash3 CreateXXHash3(CountingBloomFilterSize size)No documentation is available.
CreateXXHash32(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterXXHash32 CreateXXHash32(CountingBloomFilterSize size)No documentation is available.
CreateXXHash64(CountingBloomFilterSize)
BloomFilter.g.cspublic static CountingBloomFilterXXHash64 CreateXXHash64(CountingBloomFilterSize size)No documentation is available.
Load overloads
Load(Stream)
CountingBloomFilter.Snapshot.csCreates a counting filter from a snapshot written by CountingBloomFilter.Save.
public static CountingBloomFilter Load(Stream stream)Parameters
streamStream- 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.csCreates a counting filter of a given type from a snapshot written by CountingBloomFilter.Save.
public static TFilter Load<TFilter>(Stream stream) where TFilter : CountingBloomFilterType parameters
TFilter- The type of the filter, such as
CountingBloomFilterXXHash128.
Parameters
streamStream- 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.csCreates a counting filter from a snapshot written by CountingBloomFilter.Save or CountingBloomFilter.SaveAsync.
public static Task<CountingBloomFilter> LoadAsync(Stream stream, CancellationToken cancellationToken = default)Parameters
streamStream- The stream to read the snapshot from. It is left positioned after the snapshot.
cancellationTokenCancellationToken- 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.csCreates 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 : CountingBloomFilterType parameters
TFilter- The type of the filter, such as
CountingBloomFilterXXHash128.
Parameters
streamStream- The stream to read the snapshot from. It is left positioned after the snapshot.
cancellationTokenCancellationToken- 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).
Save(Stream)
CountingBloomFilter.Snapshot.csWrites a snapshot of the filter to a stream: its hash algorithm, its size and its counters.
Parameters
streamStream- 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.csWrites 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
streamStream- The stream to write the snapshot to.
cancellationTokenCancellationToken- 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.