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
impl AtomicBitSet
sourcepub fn new() -> Self
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());
sourcepub fn capacity(&self) -> usize
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());
sourcepub fn set(&self, position: usize)
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));
sourcepub fn into_local(self) -> BitSet
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));
sourcepub fn as_local_mut(&mut self) -> &mut BitSet
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));