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§
Required Methods§
Provided Methods§
Sourcefn hash_conflict<Q>(&self, key: &Q) -> u64
fn hash_conflict<Q>(&self, key: &Q) -> u64
if you want a 128bit hashes, you should implement this method, or leave this method return 0
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.