pub struct ArcSwapMap<K, V, S = DefaultHashBuilder> { /* private fields */ }Expand description
A concurrent HashMap backed by an ArcSwap, offering lock-free reads
and copy-on-write writes.
Reads load the current snapshot without blocking writers. Writes clone the whole map, apply their change, and atomically publish the new version, so a reader always observes a consistent snapshot and writers never block readers.
This is the shared building block behind the session-scoped registries (the
plugin registries as well as the optimizer-kernel and aggregate-function
registries) and the VortexSession type-map itself.
Because every write clones the entire map, it is intended for maps that are
written rarely (typically only while a session is being configured) and read
often.
The map is held behind an Arc so that Clone shares the same
underlying cell: a registry mutated through one clone is observed by all
others. Session variables rely on this so that encodings registered after a
session is built remain visible to clones of that session.
Implementations§
Source§impl<K, V, S> ArcSwapMap<K, V, S>
impl<K, V, S> ArcSwapMap<K, V, S>
Source§impl<K: Eq + Hash, V, S: BuildHasher> ArcSwapMap<K, V, S>
impl<K: Eq + Hash, V, S: BuildHasher> ArcSwapMap<K, V, S>
Sourcepub fn get<Q>(&self, key: &Q) -> Option<V>
pub fn get<Q>(&self, key: &Q) -> Option<V>
Return a clone of the value stored under key, if present.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns whether a value is stored under key.
pub fn insert(&self, key: K, value: V)
Sourcepub fn insert_if_absent(&self, key: K, value: V)
pub fn insert_if_absent(&self, key: K, value: V)
Insert value under key only if no value is stored there yet.
If a concurrent writer publishes a value under key first, that value
is kept and value is dropped. value is constructed by the caller
before this call, so no user code runs while the map is being updated.