BitSet structv0.1.0

Source
A growable set of bits.
pub struct BitSet {
    // private fields
}

Move-only: it owns its words.

Constructors

BitSet

pub func BitSet(allocator: Allocator) -> BitSet

An empty set that spans no bits and has allocated nothing.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: the set

Source

Methods

Length

pub func Length(self: &BitSet) -> uint

How many bits the set spans, set or not.

Returns: the length in bits

Source

Resize

pub func Resize(
    self: &var BitSet,
    length: uint
) -> ! CollectionError

Spans length bits: new bits are unset, and bits past a shorter length are dropped.

NameTypeDescription
lengthuintthe length in bits

Returns: nothing, or why there was no room

Source

Get

pub func Get(self: &BitSet, index: uint) -> bool

Whether bit index is set; false for one past the length.

NameTypeDescription
indexuintthe bit

Returns: whether it is set

Source

Set

pub func Set(
    self: &var BitSet,
    index: uint
) -> ! CollectionError

Sets bit index, growing the set to span it.

NameTypeDescription
indexuintthe bit

Returns: nothing, or why there was no room to grow

Source

Reset

pub func Reset(self: &var BitSet, index: uint)

Unsets bit index. A bit past the length is already unset.

NameTypeDescription
indexuintthe bit

Source

Toggle

pub func Toggle(
    self: &var BitSet,
    index: uint
) -> ! CollectionError

Flips bit index, growing the set to span it.

NameTypeDescription
indexuintthe bit

Returns: nothing, or why there was no room to grow

Source

Count

pub func Count(self: &BitSet) -> uint

How many bits are set.

Returns: the count

Source

IsEmpty

pub func IsEmpty(self: &BitSet) -> bool

Whether no bit is set.

Returns: whether the set is empty

Source

Clear

pub func Clear(self: &var BitSet)

Unsets every bit, keeping the length.

Source

NextSet

pub func NextSet(self: &BitSet, from: uint) -> uint?

The lowest set bit at or after from, which walks the set in order.

NameTypeDescription
fromuintwhere to start looking

Returns: the bit, or none when no bit there or after is set

Source

UnionWith

pub func UnionWith(
    self: &var BitSet,
    other: &BitSet
) -> ! CollectionError

Sets every bit that is set in other, growing to span it.

NameTypeDescription
other&BitSetthe other set

Returns: nothing, or why there was no room to grow

Source

IntersectWith

pub func IntersectWith(self: &var BitSet, other: &BitSet)

Unsets every bit that is not set in other.

NameTypeDescription
other&BitSetthe other set

Source

DifferenceWith

pub func DifferenceWith(self: &var BitSet, other: &BitSet)

Unsets every bit that is set in other.

NameTypeDescription
other&BitSetthe other set

Source

Equals

pub func Equals(self: &BitSet, other: &BitSet) -> bool

Whether the same bits are set in both, whatever their lengths.

NameTypeDescription
other&BitSetthe other set

Returns: whether they hold the same members

Source