[−][src]Trait associative_cache::Indices
Given a cache key, return all the slots within the cache where its entry might be.
Associativity
The associativity of a cache is how many slots in the cache a key might reside in. There are generally many more possible values than there is capacity in the cache. Allowing a entry to be in one of multiple slots within the cache raises the cache hit rate, but takes a little extra time when querying the cache because each of those multiple slots need to be considered.
-
Direct-mapped: A cache key corresponds to only one possible slot in the cache.
-
Two-way: A cache key corresponds to two possible slots in the cache.
-
Four-way: A cache key corresponds to four possible slots in the cache.
-
Etc...
Wikipedia has more details on cache associativity.
Provided Implementations
This crate provides two flavors of associativity out of the box:
-
Hash
-based implementations:HashDirectMapped
andHash{Two,Four,Eight,Sixteen,ThirtyTwo}Way
provide various associativity levels based on the key'sHash
implementation. -
Pointer-based implementations:
PointerDirectMapped
andPointer{Two,Four,Eight,Sixteen,ThirtyTwo}Way
provide various associativity levels based on the pointer value, taking advantage of its referenced type's alignment. This will generally provide faster lookups than hashing, but is less general.
Custom Implementation Requirements
Implementations must be determinisitc.
All indices yielded must be within the capacity.
The iterator must always be non-empty.
For example, to implement a two-way cache, return an iterator of two indices.
Associated Types
type Indices: ExactSizeIterator<Item = usize>
The iterator over indices within the range 0..C::CAPACITY
yielding the
slots in the cache where the key's entry might reside.
Required methods
fn indices(key: &K) -> Self::Indices
Get the indices within the range 0..C::CAPACITY
representing slots in
the cache where the given key's entry might reside.
Implementors
impl<T, C> Indices<*const T, C> for PointerDirectMapped where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*const T, C> for PointerEightWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*const T, C> for PointerFourWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*const T, C> for PointerSixteenWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*const T, C> for PointerThirtyTwoWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*const T, C> for PointerTwoWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerDirectMapped where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerEightWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerFourWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerSixteenWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerThirtyTwoWay where
C: Capacity,
[src]
C: Capacity,
impl<T, C> Indices<*mut T, C> for PointerTwoWay where
C: Capacity,
[src]
C: Capacity,
impl<T: ?Sized, C, H> Indices<T, C> for HashDirectMapped<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,
impl<T: ?Sized, C, H> Indices<T, C> for HashEightWay<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,
impl<T: ?Sized, C, H> Indices<T, C> for HashFourWay<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,
impl<T: ?Sized, C, H> Indices<T, C> for HashSixteenWay<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,
impl<T: ?Sized, C, H> Indices<T, C> for HashThirtyTwoWay<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,
impl<T: ?Sized, C, H> Indices<T, C> for HashTwoWay<H> where
T: Hash,
C: Capacity,
H: Hasher + Default,
[src]
T: Hash,
C: Capacity,
H: Hasher + Default,