pub struct AtomicMap<K, V>(/* private fields */);Expand description
A lock-free concurrent map optimized for read-heavy access patterns.
Reads are a single atomic pointer load with no contention between readers. Writes clone the inner map, mutate the clone, and atomically swap it in.
Not safe for concurrent writers using load/store: the last store wins
and earlier updates are silently lost. Use rcu when multiple
writers may race, or restrict writes to a single task.
Wrap in Arc for shared ownership across threads.
Implementations§
Source§impl<K, V> AtomicMap<K, V>
impl<K, V> AtomicMap<K, V>
Source§impl<K, V> AtomicMap<K, V>
impl<K, V> AtomicMap<K, V>
Sourcepub fn rcu<F>(&self, f: F)
pub fn rcu<F>(&self, f: F)
Atomically applies f to a clone of the inner map.
Retries if another writer swapped the map between the clone and the
compare-and-swap, so f may run more than once.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the map contains the given key.
Sourcepub fn get_cloned(&self, key: &K) -> Option<V>
pub fn get_cloned(&self, key: &K) -> Option<V>
Returns a clone of the value for the given key, if present.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> !Freeze for AtomicMap<K, V>
impl<K, V> RefUnwindSafe for AtomicMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for AtomicMap<K, V>
impl<K, V> Sync for AtomicMap<K, V>
impl<K, V> Unpin for AtomicMap<K, V>
impl<K, V> UnsafeUnpin for AtomicMap<K, V>
impl<K, V> UnwindSafe for AtomicMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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