Skip to main content

ArcSwapMap

Struct ArcSwapMap 

Source
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>

Source

pub fn snapshot(&self) -> Arc<HashMap<K, V, S>>

Return the currently published map snapshot.

Source

pub fn read<R>(&self, f: impl FnOnce(&HashMap<K, V, S>) -> R) -> R

Read the current snapshot, passing it to f.

Every lookup inside f observes the same snapshot, which matters when a single logical read consults more than one key.

Source§

impl<K: Eq + Hash, V, S: BuildHasher> ArcSwapMap<K, V, S>

Source

pub fn get<Q>(&self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized, V: Clone,

Return a clone of the value stored under key, if present.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns whether a value is stored under key.

Source

pub fn insert(&self, key: K, value: V)
where K: Clone, V: Clone, S: Clone,

Source

pub fn insert_if_absent(&self, key: K, value: V)
where K: Clone, V: Clone, S: Clone,

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.

Source§

impl<K: Eq + Hash + Clone, T: Clone, S: BuildHasher + Clone> ArcSwapMap<K, Arc<[T]>, S>

Source

pub fn extend(&self, key: K, values: &[T])

Append values to the list stored under key, creating it if absent.

Each key maps to an immutable Arc<[T]>; appending rebuilds that slice copy-on-write so existing readers keep their previous snapshot.

Source

pub fn push(&self, key: K, value: T)

Append a single value to the list stored under key, creating it if absent.

Trait Implementations§

Source§

impl<K, V, S> Clone for ArcSwapMap<K, V, S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug, S> Debug for ArcSwapMap<K, V, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, S: Default> Default for ArcSwapMap<K, V, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V, S> Freeze for ArcSwapMap<K, V, S>

§

impl<K, V, S> RefUnwindSafe for ArcSwapMap<K, V, S>

§

impl<K, V, S> Send for ArcSwapMap<K, V, S>
where S: Sync + Send, K: Sync + Send, V: Sync + Send,

§

impl<K, V, S> Sync for ArcSwapMap<K, V, S>
where S: Sync + Send, K: Sync + Send, V: Sync + Send,

§

impl<K, V, S> Unpin for ArcSwapMap<K, V, S>

§

impl<K, V, S> UnsafeUnpin for ArcSwapMap<K, V, S>

§

impl<K, V, S> UnwindSafe for ArcSwapMap<K, V, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.