Skip to main content

CuckooConfigurationBuilder

Struct CuckooConfigurationBuilder 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V