pub struct HopscotchMap<K: 'static, V: 'static, S = FixedState> { /* private fields */ }Expand description
A concurrent, lock-free hash map based on Hopscotch Hashing.
Implementations§
Source§impl<K, V> HopscotchMap<K, V, FixedState>
impl<K, V> HopscotchMap<K, V, FixedState>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new HopscotchMap with the specified capacity and default hasher.
Source§impl<K, V, S> HopscotchMap<K, V, S>
impl<K, V, S> HopscotchMap<K, V, S>
Sourcepub fn with_hasher(hasher: S) -> Self
pub fn with_hasher(hasher: S) -> Self
Creates a new HopscotchMap with the specified hasher and default capacity.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
Creates a new HopscotchMap with the specified capacity and hasher.
Sourcepub fn get_or_insert(&self, key: K, value: V) -> V
pub fn get_or_insert(&self, key: K, value: V) -> V
Returns the value corresponding to the key, or inserts the given value if the key is not present.
When multiple threads call this concurrently for the same key (without concurrent removes), all callers receive the same value.
Sourcepub fn insert_if_absent(&self, key: K, value: V) -> Option<V>
pub fn insert_if_absent(&self, key: K, value: V) -> Option<V>
Insert a key-value pair only if the key does not exist.
Returns None if inserted, Some(existing_value) if the key already exists.
Sourcepub fn force_remove<Q>(&self, key: &Q) -> Option<V>
pub fn force_remove<Q>(&self, key: &Q) -> Option<V>
Remove all nodes matching key, returning the most recent value
if the key was present.
remove unlinks only the first matching entry.
Insert/remove races can transiently leave more than one entry for
the same key (“versions”); after a plain remove() an older version
would become visible again. This method keeps removing until a full
scan finds no match, so the key is guaranteed absent at the
linearization point of the final scan.
Use remove() for single-version removal semantics and
force_remove() when the key must be fully evicted.
Note: a concurrent insert of the same key can land after the final
scan, as with any removal under contention.
Sourcepub fn remove<Q>(&self, key: &Q) -> Option<V>
pub fn remove<Q>(&self, key: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
Sourcepub fn iter(&self) -> HopscotchIter<'_, K, V, S> ⓘ
pub fn iter(&self) -> HopscotchIter<'_, K, V, S> ⓘ
Returns an iterator over the map entries.
Sourcepub fn keys(&self) -> HopscotchKeys<'_, K, V, S> ⓘ
pub fn keys(&self) -> HopscotchKeys<'_, K, V, S> ⓘ
Returns an iterator over the map keys.
Sourcepub fn values(&self) -> HopscotchValues<'_, K, V, S> ⓘ
pub fn values(&self) -> HopscotchValues<'_, K, V, S> ⓘ
Returns an iterator over the map values (clones V).
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the key is present.
Sourcepub fn extend<I: IntoIterator<Item = (K, V)>>(&self, iter: I)
pub fn extend<I: IntoIterator<Item = (K, V)>>(&self, iter: I)
Insert all (K, V) pairs from iter. Takes &self (concurrent map).
Trait Implementations§
Source§impl<K, V> Default for HopscotchMap<K, V, FixedState>
Available on crate feature std only.
impl<K, V> Default for HopscotchMap<K, V, FixedState>
std only.