pub struct RcuRawHashMap<K, V, S = RapidBuildHasher>where
K: Eq + Hash + Clone + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Send + Sync + 'static,{ /* private fields */ }Expand description
A hash map that uses read-copy-update (RCU) to manage concurrent accesses.
By default, this map uses rapidhash::RapidBuildHasher, which provides high performance.
However, if this map holds keys which may be attacker-controlled, consider using
std::collections::hash_map::RandomState instead.
Implementations§
Source§impl<K, V> RcuRawHashMap<K, V, RapidBuildHasher>
impl<K, V> RcuRawHashMap<K, V, RapidBuildHasher>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new hash map with the given capacity.
Source§impl<K, V, S> RcuRawHashMap<K, V, S>
impl<K, V, S> RcuRawHashMap<K, V, S>
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates a new hash map with the given capacity and hasher.
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates a new hash map with the given hasher.
Sourcepub fn get<'a, Q>(&self, scope: &'a RcuReadScope, key: &Q) -> Option<&'a V>
pub fn get<'a, Q>(&self, scope: &'a RcuReadScope, key: &Q) -> Option<&'a V>
Returns a reference to the value corresponding to the key.
Another thread running concurrently might see a different value for the object.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of entries in the map.
The length can change concurrently with this call.
Sourcepub unsafe fn insert(
&self,
scope: &RcuReadScope,
key: K,
value: V,
) -> InsertionResult<V>
pub unsafe fn insert( &self, scope: &RcuReadScope, key: K, value: V, ) -> InsertionResult<V>
Inserts a key-value pair into the map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned.
Concurrent readers might not see the inserted value until the RCU state machine has made sufficient progress to ensure that no concurrent readers are holding read guards.
§Safety
Requires external synchronization to exclude concurrent writers.
Sourcepub unsafe fn remove<Q>(&self, key: &Q) -> Option<V>
pub unsafe 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.
Concurrent readers might see the removed value until the RCU state machine has made sufficient progress to ensure that no concurrent readers are holding read guards.
§Safety
Requires external synchronization to exclude concurrent writers.
Sourcepub fn cursor<'a>(
&'a self,
scope: &'a RcuReadScope,
) -> RcuRawHashMapCursor<'a, K, V, S>
pub fn cursor<'a>( &'a self, scope: &'a RcuReadScope, ) -> RcuRawHashMapCursor<'a, K, V, S>
Returns a cursor that can be used to traverse and modify the map.
The cursor iterates through the map in insertion order.
Sourcepub fn keys<'a>(
&'a self,
scope: &'a RcuReadScope,
) -> impl Iterator<Item = &'a K>
pub fn keys<'a>( &'a self, scope: &'a RcuReadScope, ) -> impl Iterator<Item = &'a K>
Returns an iterator over the keys in the map.