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

Create an empty map.

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.

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.

Get cloned copies of the metadata and value associated with key.

Fetches the total number of storage items in the map.

This will be at most self.len_pointers().

Fetches the total number of pointers stored in the map.

This will be at least self.len_storage().

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.

Checks if the map contains a specific key.

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more