Skip to main content

SetAssociativeCache

Struct SetAssociativeCache 

Source
pub struct SetAssociativeCache<E: KeyExtract, S: BuildHasher, L: CacheLayout, A: Allocator = Global> {
    pub metrics: Metrics,
    /* private fields */
}
Expand description

A set-associative cache with CLOCK eviction, SIMD tag matching, and custom allocator support.

Fields§

§metrics: Metrics

Cache hit/miss metrics.

Implementations§

Source§

impl<E: KeyExtract, S: BuildHasher + Default, L: CacheLayout> SetAssociativeCache<E, S, L>
where E::Key: Hash + Eq,

Source

pub fn new(value_count_max: u64) -> Self

Create a new cache with default hasher and global allocator.

Source§

impl<E: KeyExtract, S: BuildHasher, L: CacheLayout> SetAssociativeCache<E, S, L>
where E::Key: Hash + Eq,

Source

pub fn with_hasher(value_count_max: u64, hash_builder: S) -> Self

Create a new cache with the given hasher and global allocator.

Source§

impl<E: KeyExtract, S: BuildHasher, L: CacheLayout, A: Allocator> SetAssociativeCache<E, S, L, A>
where E::Key: Hash + Eq,

Source

pub fn with_hasher_and_alloc( value_count_max: u64, hash_builder: S, alloc: A, ) -> Self

Create a new cache with the given hasher and allocator.

Source

pub fn value_count_max_multiple() -> u64

Minimum alignment multiple that value_count_max must satisfy.

Source

pub fn reset(&mut self)

Reset the cache, clearing all entries and metrics.

Source

pub fn get_index<Q>(&mut self, key: &Q) -> Option<usize>
where Q: Hash + Equivalent<E::Key> + ?Sized,

Look up a key, returning its index if found.

Source

pub fn get<Q>(&mut self, key: &Q) -> Option<&E::Value>
where Q: Hash + Equivalent<E::Key> + ?Sized,

Look up a key, returning a reference to the value if found.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut E::Value>
where Q: Hash + Equivalent<E::Key> + ?Sized,

Look up a key, returning a mutable reference to the value if found.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<E::Value>
where Q: Hash + Equivalent<E::Key> + ?Sized,

Remove a key from the cache if present.

Source

pub fn demote<Q>(&mut self, key: &Q)
where Q: Hash + Equivalent<E::Key> + ?Sized,

Hint that the key is less likely to be accessed in the future.

Source

pub fn upsert(&mut self, value: E::Value) -> UpsertResult<E::Value>

Upsert a value, evicting an older entry if needed.

Trait Implementations§

Source§

impl<E: KeyExtract, S: BuildHasher, L: CacheLayout, A: Allocator> Drop for SetAssociativeCache<E, S, L, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<E, S, L, A> Freeze for SetAssociativeCache<E, S, L, A>
where S: Freeze, A: Freeze,

§

impl<E, S, L, A> RefUnwindSafe for SetAssociativeCache<E, S, L, A>

§

impl<E, S, L, A = Global> !Send for SetAssociativeCache<E, S, L, A>

§

impl<E, S, L, A = Global> !Sync for SetAssociativeCache<E, S, L, A>

§

impl<E, S, L, A> Unpin for SetAssociativeCache<E, S, L, A>
where S: Unpin, A: Unpin, E: Unpin, L: Unpin,

§

impl<E, S, L, A> UnsafeUnpin for SetAssociativeCache<E, S, L, A>
where S: UnsafeUnpin, A: UnsafeUnpin,

§

impl<E, S, L, A> UnwindSafe for SetAssociativeCache<E, S, L, A>

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.