pub struct RcuHashMap<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 concurrent hash map that uses RCU for read synchronization and a mutex for write synchronization.
This map allows concurrent readers to access entries without blocking, while writers are
synchronized via a Mutex.
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, S> RcuHashMap<K, V, S>
impl<K, V, S> RcuHashMap<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 associated with the given key, if it exists.
The returned reference is bound to the lifetime of the RcuReadScope.
Sourcepub fn lock(&self) -> RcuHashMapGuard<'_, K, V, S>
pub fn lock(&self) -> RcuHashMapGuard<'_, K, V, S>
Locks the map for exclusive access, returning a guard that allows mutation.
Sourcepub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the map, returning the old value if the key was already present.
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 if the key was present.
Sourcepub fn iter<'a>(
&'a self,
scope: &'a RcuReadScope,
) -> impl Iterator<Item = (&'a K, &'a V)>
pub fn iter<'a>( &'a self, scope: &'a RcuReadScope, ) -> impl Iterator<Item = (&'a K, &'a V)>
Returns an iterator over the map’s entries.
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 map’s keys.
Trait Implementations§
Source§impl<K, V, S> Debug for RcuHashMap<K, V, S>
impl<K, V, S> Debug for RcuHashMap<K, V, S>
Auto Trait Implementations§
impl<K, V, S = BuildHasherDefault<RapidHasher>> !Freeze for RcuHashMap<K, V, S>
impl<K, V, S = BuildHasherDefault<RapidHasher>> !RefUnwindSafe for RcuHashMap<K, V, S>
impl<K, V, S> Send for RcuHashMap<K, V, S>
impl<K, V, S> Sync for RcuHashMap<K, V, S>
impl<K, V, S> Unpin for RcuHashMap<K, V, S>
impl<K, V, S> UnsafeUnpin for RcuHashMap<K, V, S>where
S: UnsafeUnpin,
impl<K, V, S> UnwindSafe for RcuHashMap<K, V, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more