Struct hibitset::AtomicBitSet

source ·
pub struct AtomicBitSet { /* private fields */ }
Expand description

This is similar to a BitSet but allows setting of value without unique ownership of the structure

An AtomicBitSet has the ability to add an item to the set without unique ownership (given that the set is big enough). Removing elements does require unique ownership as an effect of the hierarchy it holds. Worst case multiple writers set the same bit twice (but only is told they set it).

It is possible to atomically remove from the set, but not at the same time as atomically adding. This is because there is no way to know if layer 1-3 would be left in a consistent state if they are being cleared and set at the same time.

AtromicBitSet resolves this race by disallowing atomic clearing of bits.

Implementations§

source§

impl AtomicBitSet

source

pub fn new() -> AtomicBitSet

Creates an empty AtomicBitSet.

source

pub fn add_atomic(&self, id: u32) -> bool

Adds id to the AtomicBitSet. Returns true if the value was already in the set.

Because we cannot safely extend an AtomicBitSet without unique ownership this will panic if the Index is out of range.

source

pub fn add(&mut self, id: u32) -> bool

Adds id to the BitSet. Returns true if the value was already in the set.

source

pub fn remove(&mut self, id: u32) -> bool

Removes id from the set, returns true if the value was removed, and false if the value was not set to begin with.

source

pub fn contains(&self, id: u32) -> bool

Returns true if id is in the set.

source

pub fn clear(&mut self)

Clear all bits in the set

Trait Implementations§

source§

impl<'a, T> BitAnd<T> for &'a AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetAnd<&'a AtomicBitSet, T>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: T) -> Self::Output

Performs the & operation. Read more
source§

impl<T> BitAnd<T> for AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetAnd<AtomicBitSet, T>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: T) -> Self::Output

Performs the & operation. Read more
source§

impl<'a, T> BitOr<T> for &'a AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetOr<&'a AtomicBitSet, T>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: T) -> Self::Output

Performs the | operation. Read more
source§

impl<T> BitOr<T> for AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetOr<AtomicBitSet, T>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: T) -> Self::Output

Performs the | operation. Read more
source§

impl BitSetLike for AtomicBitSet

source§

fn layer3(&self) -> usize

Return a usize where each bit represents if any word in layer2 has been set.
source§

fn layer2(&self, i: usize) -> usize

Return the usize from the array of usizes that indicates if any bit has been set in layer1
source§

fn layer1(&self, i: usize) -> usize

Return the usize from the array of usizes that indicates if any bit has been set in layer0
source§

fn layer0(&self, i: usize) -> usize

Return a usize that maps to the direct 1:1 association with each index of the set
source§

fn contains(&self, i: u32) -> bool

Allows checking if set bit is contained in the bit set.
source§

fn get_from_layer(&self, layer: usize, idx: usize) -> usize

Gets the usize corresponding to layer and index. Read more
source§

fn is_empty(&self) -> bool

Returns true if this BitSetLike contains nothing, and false otherwise.
source§

fn iter(self) -> BitIter<Self> where Self: Sized,

Create an iterator that will scan over the keyspace
source§

fn par_iter(self) -> BitParIter<Self>where Self: Sized,

Create a parallel iterator that will scan over the keyspace
source§

impl<'a, T> BitXor<T> for &'a AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetXor<&'a AtomicBitSet, T>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: T) -> Self::Output

Performs the ^ operation. Read more
source§

impl<T> BitXor<T> for AtomicBitSetwhere T: BitSetLike,

§

type Output = BitSetXor<AtomicBitSet, T>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: T) -> Self::Output

Performs the ^ operation. Read more
source§

impl Debug for AtomicBitSet

source§

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

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

impl Default for AtomicBitSet

source§

fn default() -> Self

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

impl DrainableBitSet for AtomicBitSet

source§

fn remove(&mut self, i: u32) -> bool

Removes bit from the bit set. Read more
source§

fn drain<'a>(&'a mut self) -> DrainBitIter<'a, Self> where Self: Sized,

Create a draining iterator that will scan over the keyspace and clears it while doing so.
source§

impl<'a> Extend<&'a u32> for AtomicBitSet

source§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = &'a u32>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<u32> for AtomicBitSet

source§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = u32>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> FromIterator<&'a u32> for AtomicBitSet

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = &'a u32>,

Creates a value from an iterator. Read more
source§

impl FromIterator<u32> for AtomicBitSet

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = u32>,

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a AtomicBitSet

§

type Item = <BitIter<&'a AtomicBitSet> as Iterator>::Item

The type of the elements being iterated over.
§

type IntoIter = BitIter<&'a AtomicBitSet>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for AtomicBitSet

§

type Item = <BitIter<AtomicBitSet> as Iterator>::Item

The type of the elements being iterated over.
§

type IntoIter = BitIter<AtomicBitSet>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> Not for &'a AtomicBitSet

§

type Output = BitSetNot<&'a AtomicBitSet>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl Not for AtomicBitSet

§

type Output = BitSetNot<AtomicBitSet>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.