pub struct HashMap<K: 'static, V: 'static, S = FixedState> { /* private fields */ }Expand description
High-Performance Lock-Free Map with automatic grow/shrink.
Implementations§
Source§impl<K, V> HashMap<K, V, FixedState>
impl<K, V> HashMap<K, V, FixedState>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty hash map with at least capacity buckets.
Source§impl<K, V, S> HashMap<K, V, S>
impl<K, V, S> HashMap<K, V, S>
Sourcepub fn with_hasher(hasher: S) -> Self
pub fn with_hasher(hasher: S) -> Self
Creates a new hash map with custom hasher.
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 hash map with at least capacity buckets and a custom hasher.
The map grows when its load factor exceeds 0.75 and shrinks when it
falls below 0.25 — but never below capacity.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<V>
pub fn get<Q>(&self, key: &Q) -> Option<V>
Optimized get operation. Never blocks — reads the current table snapshot under a guard, even while a resize is in flight.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Checks if the key exists.
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 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.
This is linearizable: concurrent callers for the same key are guaranteed to agree on which value was inserted (exactly one thread’s CAS succeeds at the list tail, and all others see that node on retry).
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 len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
O(1): maintained by insert/remove. Approximate while concurrent
updates are in flight (exact in quiescence), like HopscotchMap.
Sourcepub fn iter(&self) -> Iter<'_, K, V, S> ⓘ
pub fn iter(&self) -> Iter<'_, K, V, S> ⓘ
Returns an iterator over the map entries. Yields (K, V) clones from a table snapshot taken at creation.
Sourcepub fn keys(&self) -> Keys<'_, K, V, S> ⓘ
pub fn keys(&self) -> Keys<'_, K, V, S> ⓘ
Returns an iterator over the map keys. Yields K clones.
Sourcepub fn values(&self) -> Values<'_, K, V, S> ⓘ
pub fn values(&self) -> Values<'_, K, V, S> ⓘ
Returns an iterator over the map values (clones V).
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 HashMap<K, V, FixedState>
Available on crate feature std only.
impl<K, V> Default for HashMap<K, V, FixedState>
std only.