Skip to main content

AtomicSet

Struct AtomicSet 

Source
pub struct AtomicSet<K>(/* private fields */);
Expand description

A lock-free concurrent set optimized for read-heavy access patterns.

Reads are a single atomic pointer load with no contention between readers. Writes clone the inner set, 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> AtomicSet<K>

Source

pub fn new() -> Self

Creates a new empty atomic set.

Source

pub fn load(&self) -> Guard<Arc<AHashSet<K>>>

Returns a snapshot guard for direct access to the inner set.

The guard dereferences to AHashSet<K>. Use for operations that need iteration or reference access.

Source

pub fn store(&self, set: AHashSet<K>)

Atomically replaces the inner set.

Source§

impl<K> AtomicSet<K>
where K: Eq + Hash + Clone,

Source

pub fn rcu<F>(&self, f: F)
where F: FnMut(&mut AHashSet<K>),

Atomically applies f to a clone of the inner set.

Retries if another writer swapped the set between the clone and the compare-and-swap, so f may run more than once.

Source

pub fn contains(&self, key: &K) -> bool

Returns true if the set contains the given key.

Source

pub fn insert(&self, key: K)

Inserts a key (clone-and-swap).

Source

pub fn remove(&self, key: &K)

Removes a key (clone-and-swap).

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn is_empty(&self) -> bool

Returns true if the set is empty.

Trait Implementations§

Source§

impl<K: Debug + Eq + Hash> Debug for AtomicSet<K>

Source§

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

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

impl<K> Default for AtomicSet<K>

Source§

fn default() -> Self

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

impl<K: Eq + Hash> From<AHashSet<K>> for AtomicSet<K>

Source§

fn from(set: AHashSet<K>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<K> !Freeze for AtomicSet<K>

§

impl<K> RefUnwindSafe for AtomicSet<K>
where K: RefUnwindSafe,

§

impl<K> Send for AtomicSet<K>
where K: Sync + Send,

§

impl<K> Sync for AtomicSet<K>
where K: Sync + Send,

§

impl<K> Unpin for AtomicSet<K>

§

impl<K> UnsafeUnpin for AtomicSet<K>

§

impl<K> UnwindSafe for AtomicSet<K>
where K: RefUnwindSafe,

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<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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Ungil for T
where T: Send,