C# Class Demo.Library.Algorithms.Bloom.CuckooBloomFilter

CuckooFilter implements a Cuckoo Bloom filter as described by Andersen, Kaminsky, and Mitzenmacher in Cuckoo Filter: Practically Better Than Bloom: http://www.pdl.cmu.edu/PDL-FTP/FS/cuckoo-conext2014.pdf A Cuckoo Filter is a Bloom filter variation which provides support for removing elements without significantly degrading space and performance. It works by using a cuckoo hashing scheme for inserting items. Instead of storing the elements themselves, it stores their fingerprints which also allows for item removal without false negatives (if you don't attempt to remove an item not contained in the filter). For applications that store many items and target moderately low false-positive rates, cuckoo filters have lower space overhead than space-optimized Bloom filters.
Afficher le fichier Open project: volak/DDD.Enterprise.Example

Private Properties

Свойство Type Description
CalculateF uint
ComputeHash byte[]
ComputeHashSum32 uint
Contains bool
GetComponents Components
GetEmptyEntry int
IndexOf int
Insert bool
Power2 uint

Méthodes publiques

Méthode Description
Add ( byte data ) : bool

Will add the data to the Cuckoo Filter. It returns false if the filter is full. If the filter is full, an item is removed to make room for the new item. This introduces a possibility for false negatives. To avoid this, use Count and Capacity to check if the filter is full before adding an item.

BucketCount ( ) : uint

Returns the number of buckets.

Capacity ( ) : uint

Returns the number of items the filter can store.

Count ( ) : uint

Returns the number of items in the filter.

CuckooBloomFilter ( uint n, double fpRate ) : System

Creates a new Cuckoo Bloom filter optimized to store n items with a specified target false-positive rate.

Reset ( ) : CuckooBloomFilter

Restores the Bloom filter to its original state. It returns the filter to allow for chaining.

SetHash ( HashAlgorithm h ) : void

Sets the hashing function used in the filter.

Test ( byte data ) : bool

Will test for membership of the data and returns true if it is a member, false if not. This is a probabilistic test, meaning there is a non-zero probability of false positives.

TestAndAdd ( byte data ) : TestAndAddReturnValue

Equivalent to calling Test followed by Add. It returns (true, false) if the data is a member, (false, add()) if not. False is returned if the filter is full. If the filter is full, an item is removed to make room for the new item. This introduces a possibility for false negatives. To avoid this, use Count and Capacity to check if the filter is full before adding an item.

TestAndRemove ( byte data ) : bool

Will test for membership of the data and remove it from the filter if it exists. Returns true if the data was a member, false if not.

Private Methods

Méthode Description
CalculateF ( uint b, double epsilon ) : uint

Returns the optimal fingerprint length in bytes for the given bucket size and false-positive rate epsilon.

ComputeHash ( byte data ) : byte[]

Returns a 32-bit hash value for the given data.

ComputeHashSum32 ( byte data ) : uint

Returns the sum of the hash.

Contains ( byte bucket, byte f ) : bool

Indicates if the given fingerprint is contained in one of the bucket's entries.

GetComponents ( byte data ) : Components

Returns the two hash values used to index into the buckets and the fingerprint for the given element.

GetEmptyEntry ( byte bucket ) : int

Returns the index of the next available entry in the bucket or -1 if it's full.

IndexOf ( byte bucket, byte f ) : int

Returns the entry index of the given fingerprint or -1 if it's not in the bucket.

Insert ( uint i1, uint i2, byte f ) : bool

Will insert the fingerprint into the filter returning false if the filter is full.

Power2 ( uint x ) : uint

Calculates the next power of two for the given value.

Method Details

Add() public méthode

Will add the data to the Cuckoo Filter. It returns false if the filter is full. If the filter is full, an item is removed to make room for the new item. This introduces a possibility for false negatives. To avoid this, use Count and Capacity to check if the filter is full before adding an item.
public Add ( byte data ) : bool
data byte
Résultat bool

BucketCount() public méthode

Returns the number of buckets.
public BucketCount ( ) : uint
Résultat uint

Capacity() public méthode

Returns the number of items the filter can store.
public Capacity ( ) : uint
Résultat uint

Count() public méthode

Returns the number of items in the filter.
public Count ( ) : uint
Résultat uint

CuckooBloomFilter() public méthode

Creates a new Cuckoo Bloom filter optimized to store n items with a specified target false-positive rate.
public CuckooBloomFilter ( uint n, double fpRate ) : System
n uint Number of items to store
fpRate double Target false-positive rate
Résultat System

Reset() public méthode

Restores the Bloom filter to its original state. It returns the filter to allow for chaining.
public Reset ( ) : CuckooBloomFilter
Résultat CuckooBloomFilter

SetHash() public méthode

Sets the hashing function used in the filter.
public SetHash ( HashAlgorithm h ) : void
h System.Security.Cryptography.HashAlgorithm The HashAlgorithm to use.
Résultat void

Test() public méthode

Will test for membership of the data and returns true if it is a member, false if not. This is a probabilistic test, meaning there is a non-zero probability of false positives.
public Test ( byte data ) : bool
data byte The data to test for
Résultat bool

TestAndAdd() public méthode

Equivalent to calling Test followed by Add. It returns (true, false) if the data is a member, (false, add()) if not. False is returned if the filter is full. If the filter is full, an item is removed to make room for the new item. This introduces a possibility for false negatives. To avoid this, use Count and Capacity to check if the filter is full before adding an item.
public TestAndAdd ( byte data ) : TestAndAddReturnValue
data byte
Résultat TestAndAddReturnValue

TestAndRemove() public méthode

Will test for membership of the data and remove it from the filter if it exists. Returns true if the data was a member, false if not.
public TestAndRemove ( byte data ) : bool
data byte Data to test for and remove
Résultat bool