pub struct CuckooConfigurationBuilder { /* private fields */ }Expand description
Builder for CuckooConfiguration.
New instance can be created using CuckooConfiguration::builder.
§Examples
use cuckoo_clock::config::CuckooConfiguration;
let builder = CuckooConfiguration::builder(100_000);Implementations§
Source§impl CuckooConfigurationBuilder
impl CuckooConfigurationBuilder
Sourcepub const fn fingerprint_bits(self, bits: BitCount) -> Self
pub const fn fingerprint_bits(self, bits: BitCount) -> Self
Sets the number of bits used for fingerprint. Higher number of bits should result in less collisions, which should result in a lower false positive rate, at the cost of increased memory usage.
Sourcepub const fn bucket_size(self, size: NonZeroUsize) -> Self
pub const fn bucket_size(self, size: NonZeroUsize) -> Self
Sets the number of buckets to hold in a bucket. Larger buckets improve filter occupancy (space utilization), but they also require larger fingerprints to retain the same false positive rate.
5.1. Optimal bucket size in the original paper describes this relation.
Sourcepub const fn max_kicks(self, kicks: usize) -> Self
pub const fn max_kicks(self, kicks: usize) -> Self
Maximum number of kicks to perform if all requested slots are occupied when inserting new items. Items will be evicted and moved to their alternate slots until no more evictions are required or maximum number of kicks is reached.
If the maximum number of kicks is reached, one item will be lost from the filter.
Increasing this number will increase filter occupancy at the cost of insertion speed.
Sourcepub const fn with_lru(self, lru: LruConfig) -> Self
pub const fn with_lru(self, lru: LruConfig) -> Self
Enables LRU eviction for the filter. Kicks will no longer be performed randomly and will always target least recently used items, until either no more evictions are required, max number of kicks was reached or the kicked item is to be moved in a bucket with all slots occupied by more used items.
When LRU is used, crate::CuckooFilter::scan_and_update_full should be called
periodically, to age LRU for all items. It is up to the caller to schedule this process.
More frequent scans will result in faster aging LRU for all items, requiring item to be
used more frequently to outlive other items.
Sourcepub const fn with_ttl(self, ttl: TtlConfig) -> Self
pub const fn with_ttl(self, ttl: TtlConfig) -> Self
Enables TTL for items in the filter. TTL will be used to expire items from the filter when
crate::CuckooFilter::scan_and_update_full is called.
When TTL is used, crate::CuckooFilter::scan_and_update_full should be called
periodically, to age TTL for all items. It is up to the caller to schedule this process.
More frequent scans will result in lower TTL for all items.
Sourcepub const fn with_counter(self, counter: CounterConfig) -> Self
pub const fn with_counter(self, counter: CounterConfig) -> Self
Enables counter for items in the filter. Counter is just provided as a value that can be read when accessing items. It is increased on every access (and can be controlled directly).
Sourcepub fn build(&self) -> Result<CuckooConfiguration, ConfigError>
pub fn build(&self) -> Result<CuckooConfiguration, ConfigError>
Validates and builds the configuration.
§Errors
ConfigError::BucketTooBig if requests buckets are too big to represent with usize::MAX.
Bucket size is defined as Self::bucket_size * item bits (sum of all fields bits,
rounded to byte).