Struct deduped_dashmap::DedupedMap
source · [−]pub struct DedupedMap<K, M, V> where
K: Eq + Hash,
M: Debug,
V: Debug, {
pub(crate) pointers: DashMap<K, MapPointer<M>>,
pub(crate) storage: DashMap<u64, MapValue<V>>,
}
Expand description
A hashmap that assumes a large number of keys will map to a relatively smaller number of values.
If a value is stored in the map that is already stored by another key, the refcount of the value will be incremented instead of duplicating it.
Uses DashMap internally
Fields
pointers: DashMap<K, MapPointer<M>>
First layer of the map. A mapping from incoming requests to a u64 pointer into the cache storage.
storage: DashMap<u64, MapValue<V>>
Second layer of the map. The items stored in the cache, keyed by their hash.
Implementations
sourceimpl<K, M, V> DedupedMap<K, M, V> where
K: Eq + Hash + Debug,
M: Debug + Clone,
V: Hash + Debug + Clone,
impl<K, M, V> DedupedMap<K, M, V> where
K: Eq + Hash + Debug,
M: Debug + Clone,
V: Hash + Debug + Clone,
sourcepub fn insert(&self, key: K, meta: M, value: V)
pub fn insert(&self, key: K, meta: M, value: V)
Insert value
into the map at key
with metadata meta
.
If value
is already in the map under a different key, its refcount will
be incremented instead of storing another copy of value
. The metadata
data meta
will be attached to this specific key, and not refcounted.
sourcepub fn remove(&self, key: K)
pub fn remove(&self, key: K)
Remove the item associated with a key from the map.
The metadata associated with key
will always be removed. The reference
count of the storage item it points to will be decremented. If no more
keys refer to the storage item, it will also be removed.
sourcepub fn get(&self, key: &K) -> Option<(M, V)>
pub fn get(&self, key: &K) -> Option<(M, V)>
Get cloned copies of the metadata and value associated with key
.
sourcepub fn len_storage(&self) -> usize
pub fn len_storage(&self) -> usize
Fetches the total number of storage items in the map.
This will be at most self.len_pointers()
.
sourcepub fn len_pointers(&self) -> usize
pub fn len_pointers(&self) -> usize
Fetches the total number of pointers stored in the map.
This will be at least self.len_storage()
.
sourcepub fn retain<F>(&self, pred: F) where
F: FnMut(&K, &M, &V) -> ControlFlow<bool>,
pub fn retain<F>(&self, pred: F) where
F: FnMut(&K, &M, &V) -> ControlFlow<bool>,
Retain elements based on the result of a predicate.
If the predicate function returns:
ControlFlow::Continue(true)
: The item will be retained and the iteration will continue.ControlFlow::Continue(false)
: The item will be removed and the iteration will continue.ControlFlow::Break(())
: This item, and all further items in the map, will be retained, and the predicate won’t be called again.
sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Checks if the map contains a specific key.
sourcepub fn clear(&self)
pub fn clear(&self)
Clears the map, both the pointer and the storage maps.
It behaves as Self::retain(|_, _, _| ControlFlow::Continue(false))
except being faster as the predicate checking step is skipped.
Note that the two underlying maps are cleared sequentially without locking, calling this function while other map mutations are done concurrently could result in dangling pointers. As a mitigation, it clears the pointer map first, followed by the storage map to reduce the chance of dangling pointers.
Trait Implementations
sourceimpl<K: Debug, M: Debug, V: Debug> Debug for DedupedMap<K, M, V> where
K: Eq + Hash,
M: Debug,
V: Debug,
impl<K: Debug, M: Debug, V: Debug> Debug for DedupedMap<K, M, V> where
K: Eq + Hash,
M: Debug,
V: Debug,
Auto Trait Implementations
impl<K, M, V> !RefUnwindSafe for DedupedMap<K, M, V>
impl<K, M, V> Send for DedupedMap<K, M, V> where
K: Send,
M: Send,
V: Send,
impl<K, M, V> Sync for DedupedMap<K, M, V> where
K: Send + Sync,
M: Send + Sync,
V: Send + Sync,
impl<K, M, V> Unpin for DedupedMap<K, M, V>
impl<K, M, V> UnwindSafe for DedupedMap<K, M, V> where
K: UnwindSafe,
M: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more