[][src]Struct compressible_map::CompressibleMap

pub struct CompressibleMap<K, V, A, H = RandomState> where
    A: Compression<Data = V>, 
{ /* fields omitted */ }

A hash map that allows compressing the least recently used values. Useful when you need to store a lot of large values in memory. You must define your own compression method for the value type using the Compressible and Decompressible traits.

Call the compress_lru method to compress the least recently used value. The most recently used values will stay uncompressed in a cache.

Any mutable access (&mut self) that misses the cache will decompress and cache the value inline. You can call get to prefetch into the cache and avoid extra latency on further accesses.

Any immutable access (&self, e.g. from multiple threads), like get_const, cannot update the cache. Instead, it will record accesses and store decompressed values in a LocalCache that can be used later to update the cache with flush_local_cache.

Implementations

impl<K, V, H, A> CompressibleMap<K, V, A, H> where
    K: Clone + Eq + Hash,
    H: BuildHasher + Default,
    A: Compression<Data = V>, 
[src]

pub fn new(compression_params: A) -> Self[src]

pub fn compression_params(&self) -> &A[src]

pub fn from_all_compressed(
    compression_params: A,
    compressed: HashMap<K, Compressed<A>, H>
) -> Self
[src]

pub fn insert(&mut self, key: K, value: V)[src]

Insert a new value and drop the old one.

pub fn insert_compressed(
    &mut self,
    key: K,
    value: Compressed<A>
) -> Option<MaybeCompressed<V, Compressed<A>>>
[src]

Insert a compressed value, returning any pre-existing entry.

pub fn replace(&mut self, key: K, value: V) -> Option<V>[src]

Insert a new value and return the old one if it exists, which requires decompressing it.

pub fn compress_lru(&mut self)[src]

pub fn remove_lru(&mut self) -> Option<(K, V)>[src]

pub fn get_mut(&mut self, key: K) -> Option<&mut V>[src]

pub fn get(&mut self, key: K) -> Option<&V>[src]

pub fn get_or_insert_with(
    &mut self,
    key: K,
    on_missing: impl FnOnce() -> V
) -> &mut V
[src]

pub fn get_const<'a>(
    &'a self,
    key: K,
    local_cache: &'a LocalCache<K, V, H>
) -> Option<&'a V>
[src]

Used for thread-safe access or to borrow multiple values at once. The cache will not be updated, but accesses will be recorded in the provided LocalCache. The interior mutability of the local cache has a cost (more heap indirection), but it allows us to borrow multiple values at once. Call flush_local_cache to update the "global" cache with the local cache.

pub fn get_copy_without_caching(&self, key: &K) -> Option<V> where
    V: Clone
[src]

Returns a copy of the value at key, which may involve decompression. WARNING: the cache will not be updated. This is useful for read-modify-write scenarios where you would just insert the modified value back into the map, which defeats the purpose of caching it on read.

pub fn flush_local_cache(&mut self, local_cache: LocalCache<K, V, H>)[src]

Updates the cache and it's approximate LRU order after calling get_const some number of times. WARNING/TODO: There is currently no mechanism to prevent overwriting newer compressed data with old data from a local cache.

pub fn drop(&mut self, key: &K)[src]

pub fn remove(&mut self, key: &K) -> Option<V>[src]

Removes the value and returns it if it exists, decompressing it first.

pub fn clear(&mut self)[src]

pub fn len(&self) -> usize[src]

pub fn len_cached(&self) -> usize[src]

pub fn len_compressed(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn keys<'a>(&'a self) -> impl Iterator<Item = &K> where
    Compressed<A>: 'a, 
[src]

pub fn iter_maybe_compressed<'a>(
    &'a self
) -> impl Iterator<Item = (&K, MaybeCompressed<&V, &Compressed<A>>)> where
    Compressed<A>: 'a, 
[src]

Iterate over all (key, value) pairs, but compressed values will not be decompressed inline. Does not affect the cache.

pub fn into_iter(
    self
) -> impl Iterator<Item = (K, MaybeCompressed<V, Compressed<A>>)>
[src]

Auto Trait Implementations

impl<K, V, A, H> RefUnwindSafe for CompressibleMap<K, V, A, H> where
    A: RefUnwindSafe,
    H: RefUnwindSafe,
    K: RefUnwindSafe,
    V: RefUnwindSafe,
    <A as Compression>::CompressedData: RefUnwindSafe

impl<K, V, A, H> Send for CompressibleMap<K, V, A, H> where
    A: Send,
    H: Send,
    K: Send,
    V: Send,
    <A as Compression>::CompressedData: Send

impl<K, V, A, H> Sync for CompressibleMap<K, V, A, H> where
    A: Sync,
    H: Sync,
    K: Sync,
    V: Sync,
    <A as Compression>::CompressedData: Sync

impl<K, V, A, H> Unpin for CompressibleMap<K, V, A, H> where
    A: Unpin,
    H: Unpin,
    K: Unpin,
    V: Unpin,
    <A as Compression>::CompressedData: Unpin

impl<K, V, A, H> UnwindSafe for CompressibleMap<K, V, A, H> where
    A: UnwindSafe,
    H: UnwindSafe,
    K: UnwindSafe,
    V: UnwindSafe,
    <A as Compression>::CompressedData: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.