Skip to main content

TwoBucket

Trait TwoBucket 

Source
pub trait TwoBucket:
    Debug
    + Default
    + Sync {
    // Required methods
    fn get(&self, hash: HashKind) -> Option<Entry>;
    fn contains(&self, hash: HashKind) -> bool;
    fn store(&self, general_entry: Entry);
    fn replace(&self, priority_entry: Entry, age: u8);
    fn swap_replace(&self, priority_entry: Entry, age: u8);
    fn replace_by<F>(&self, entry: Entry, age: u8, should_replace: F)
       where F: FnOnce(&Entry, u8, &Entry, u8) -> bool;
    fn swap_replace_by<F>(&self, entry: Entry, age: u8, should_replace: F)
       where F: FnOnce(&Entry, u8, &Entry, u8) -> bool;

    // Provided method
    fn len() -> usize { ... }
}
Expand description

Transposition Table Bucket that holds 2 entries, consisting of a priority slot and a general slot.

Required Methods§

Source

fn get(&self, hash: HashKind) -> Option<Entry>

Returns an entry if its corresponding hash exists in this bucket. If no entry’s hash matches the given hash, returns None.

Source

fn contains(&self, hash: HashKind) -> bool

Returns true if this bucket has any entry which contains the given hash.

Source

fn store(&self, general_entry: Entry)

Unconditionally store the entry in the general slot, without updating age.

Source

fn replace(&self, priority_entry: Entry, age: u8)

Unconditionally place the entry in the priority slot and update age.

Source

fn swap_replace(&self, priority_entry: Entry, age: u8)

Move the existing priority entry to the general slot, then place the new priority entry into the priority slot and update age.

Source

fn replace_by<F>(&self, entry: Entry, age: u8, should_replace: F)
where F: FnOnce(&Entry, u8, &Entry, u8) -> bool,

Replaces the priority slot if should_replace returns true, otherwise the general slot is replaced.

§Example:

if should_replace { priority := entry } else { general := entry }

FnOnce signature:

should_replace(&new_entry, new_age, &existing_priority_entry, existing_age) -> bool

Source

fn swap_replace_by<F>(&self, entry: Entry, age: u8, should_replace: F)
where F: FnOnce(&Entry, u8, &Entry, u8) -> bool,

If should_replace returns true, then swap_replace with the given entry.

Example:

if should_replace { general := priority priority := entry } else { general := entry }

FnOnce signature:

should_replace(&new_entry, new_age, &existing_priority_entry, existing_age) -> bool

Provided Methods§

Source

fn len() -> usize

The number of entries held by this bucket.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§