Struct uniset::AtomicBitSet

source ·
#[repr(C)]
pub struct AtomicBitSet { /* private fields */ }
Expand description

The same as BitSet, except it provides atomic methods.

BitSet and AtomicBitSet’s are guaranteed to have an identical memory layout, so they support zero-cost back and forth conversion.

The as_local_mut and into_local methods can be used to convert to a local unsynchronized bitset.

Implementations§

source§

impl AtomicBitSet

source

pub fn new() -> Self

Construct a new, empty atomic bit set.

§Examples
use uniset::AtomicBitSet;

let set = AtomicBitSet::new();
let set = set.into_local();
assert!(set.is_empty());
source

pub fn capacity(&self) -> usize

Get the current capacity of the bitset.

§Examples
use uniset::AtomicBitSet;

let set = AtomicBitSet::new();
assert_eq!(0, set.capacity());
source

pub fn set(&self, position: usize)

Set the given bit atomically.

We can do this to an AtomicBitSet since the required modifications that needs to be performed against each layer are idempotent of the order in which they are applied.

§Panics

Call will panic if the position is not within the capacity of the AtomicBitSet.

§Examples
use uniset::BitSet;

let set = BitSet::with_capacity(1024).into_atomic();
set.set(1000);
let set = set.into_local();
assert!(set.test(1000));
source

pub fn into_local(self) -> BitSet

Convert in-place into a a BitSet.

This is safe, since this function requires exclusive owned access to the AtomicBitSet, and we assert that their memory layouts are identical.

§Examples
use uniset::BitSet;

let mut set = BitSet::new();
set.reserve(1024);

let atomic = set.into_atomic();
atomic.set(42);

let set = atomic.into_local();
assert!(set.test(42));
source

pub fn as_local_mut(&mut self) -> &mut BitSet

Convert in-place into a mutable reference to a BitSet.

This is safe, since this function requires exclusive mutable access to the AtomicBitSet, and we assert that their memory layouts are identical.

§Examples
use uniset::BitSet;

let mut set = BitSet::with_capacity(1024).into_atomic();

set.set(21);
set.set(42);

{
    let set = set.as_local_mut();
    // Clearing is only safe with BitSet's since we require exclusive
    // mutable access to the collection being cleared.
    set.clear(21);
}

let set = set.into_local();
assert!(!set.test(21));
assert!(set.test(42));

Trait Implementations§

source§

impl Default for AtomicBitSet

source§

fn default() -> Self

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

Auto Trait Implementations§

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, U> TryFrom<U> for T
where 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 T
where 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.