Skip to main content

KeyBuilder

Trait KeyBuilder 

Source
pub trait KeyBuilder {
    type Key: Hash + Eq + ?Sized;

    // Required method
    fn hash_index<Q>(&self, key: &Q) -> u64
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + ?Sized;

    // Provided methods
    fn hash_conflict<Q>(&self, key: &Q) -> u64
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + ?Sized { ... }
    fn build_key<Q>(&self, k: &Q) -> (u64, u64)
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + ?Sized { ... }
}
Expand description

KeyBuilder is the hashing algorithm used for every key. In Stretto, the Cache will never store the real key. The key will be processed by KeyBuilder. Stretto has two default built-in key builder, one is TransparentKeyBuilder, the other is DefaultKeyBuilder. If your key implements TransparentKey trait, you can use TransparentKeyBuilder which is faster than DefaultKeyBuilder. Otherwise, you should use DefaultKeyBuilder You can also write your own key builder for the Cache, by implementing KeyBuilder trait.

Note that if you want 128bit hashes you should use the full (u64, u64), otherwise just fill the u64 at the 0 position, and it will behave like any 64bit hash.

Required Associated Types§

Source

type Key: Hash + Eq + ?Sized

Key

Required Methods§

Source

fn hash_index<Q>(&self, key: &Q) -> u64
where Self::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

hash_index is used to hash the key to u64

Provided Methods§

Source

fn hash_conflict<Q>(&self, key: &Q) -> u64
where Self::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

if you want a 128bit hashes, you should implement this method, or leave this method return 0

Source

fn build_key<Q>(&self, k: &Q) -> (u64, u64)
where Self::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

build the key to 128bit hashes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§