[][src]Struct unicycle::BitSet

#[repr(C)]
pub struct BitSet { /* fields omitted */ }

A sparse, layered bit set.

Layered bit sets support exceedingly efficient iteration, union, and intersection operations since they maintain summary layers summarizing the bits which are sets in layers below it.

BitSet and AtomicBitSet's are guaranteed to have an identical memory layout, so while it would require unsafe, transmuting or coercing between the two is sound assuming the proper synchronization is respected.

A BitSet provides the following methods for converting to an AtomicBitSet: into_atomic and as_atomic.

Methods

impl BitSet[src]

pub fn new() -> Self[src]

Construct a new, empty BitSet with an empty capacity.

Examples

use unicycle::BitSet;

let mut set = BitSet::new();
assert!(set.is_empty());
assert_eq!(0, set.capacity());

pub fn with_capacity(capacity: usize) -> Self[src]

Construct a new, empty BitSet with the specified capacity.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(1024);
assert!(set.is_empty());
assert_eq!(1024, set.capacity());

pub fn is_empty(&self) -> bool[src]

Test if the bit set is empty.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(64);
assert!(set.is_empty());
set.set(2);
assert!(!set.is_empty());
set.clear(2);
assert!(set.is_empty());

pub fn capacity(&self) -> usize[src]

Get the current capacity of the bitset.

Examples

use unicycle::BitSet;

let mut set = BitSet::new();
assert!(set.is_empty());
assert_eq!(0, set.capacity());

pub fn layers(&self) -> Vec<&[usize]>[src]

Return a view of the underlying, raw layers.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(128);
set.set(1);
set.set(5);
// Note: two layers since we specified a capacity of 128.
assert_eq!(vec![&[0b100010, 0][..], &[1]], set.layers());

pub fn into_atomic(self) -> AtomicBitSet[src]

Convert in-place into an AtomicBitSet.

Atomic bit sets uses structural sharing with the current set, so this is a constant time O(1) operation.

Examples

use unicycle::BitSet;

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

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

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

pub fn as_atomic(&self) -> &AtomicBitSet[src]

Convert in-place into a reference to an AtomicBitSet.

Examples

use unicycle::BitSet;

let set = BitSet::with_capacity(1024);

set.as_atomic().set(42);
assert!(set.test(42));

pub fn set(&mut self, position: usize)[src]

Set the given bit.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(64);

assert!(set.is_empty());
set.set(2);
assert!(!set.is_empty());

pub fn clear(&mut self, position: usize)[src]

Clear the given bit.

Panics

Panics if the position does not fit within the capacity of the BitSet.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(64);

set.clear(2);
assert!(set.is_empty());
set.set(2);
assert!(!set.is_empty());
set.clear(2);
assert!(set.is_empty());
set.clear(2);
assert!(set.is_empty());

pub fn test(&self, position: usize) -> bool[src]

Test if the given position is set.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(64);

assert!(set.is_empty());
set.set(2);
assert!(!set.is_empty());
assert!(set.test(2));
assert!(!set.test(3));

pub fn reserve(&mut self, cap: usize)[src]

Reserve enough space to store the given number of elements.

This will not reserve space for exactly as many elements specified, but will round up to the closest order of magnitude of 2.

Examples

use unicycle::BitSet;
let mut set = BitSet::with_capacity(128);
assert_eq!(128, set.capacity());
set.reserve(250);
assert_eq!(256, set.capacity());

Important traits for Drain<'_>
pub fn drain(&mut self) -> Drain[src]

Create a draining iterator over the bitset, yielding all elements in order of their index.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(128);
set.set(127);
set.set(32);
set.set(3);

assert_eq!(vec![3, 32, 127], set.drain().collect::<Vec<_>>());
assert!(set.is_empty());

Draining one bit at a time.

use unicycle::BitSet;

let mut set = BitSet::with_capacity(128);

set.set(127);
set.set(32);
set.set(3);

assert_eq!(Some(3), set.drain().next());
assert_eq!(Some(32), set.drain().next());
assert_eq!(Some(127), set.drain().next());
assert!(set.is_empty());

Saving the state of the draining iterator.

use unicycle::BitSet;

let mut set = BitSet::with_capacity(128);

set.set(127);
set.set(32);
set.set(3);

let mut it = set.drain();

assert_eq!(Some(3), it.next());
assert_eq!(Some(32), it.next());
assert!(it.snapshot().is_some());
assert_eq!(Some(127), it.next());
assert!(it.snapshot().is_none());
assert_eq!(None, it.next());
assert!(it.snapshot().is_none());

Important traits for Drain<'_>
pub fn drain_from(&mut self, DrainSnapshot: DrainSnapshot) -> Drain[src]

Start a drain operation using the given configuration parameters.

These are usually acquired from [Drain::save], and can be used to resume draining at a specific point.

Important traits for Iter<'_>
pub fn iter(&self) -> Iter[src]

Create an iterator over the bitset, yielding all elements in order of their index.

Note that iterator allocates a vector with a size matching the number of layers in the BitSet.

Examples

use unicycle::BitSet;

let mut set = BitSet::with_capacity(128);
set.set(127);
set.set(32);
set.set(3);

assert_eq!(vec![3, 32, 127], set.iter().collect::<Vec<_>>());
assert!(!set.is_empty());

Trait Implementations

impl Clone for BitSet[src]

impl Default for BitSet[src]

Auto Trait Implementations

impl RefUnwindSafe for BitSet

impl Send for BitSet

impl Sync for BitSet

impl Unpin for BitSet

impl UnwindSafe for BitSet

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.