BitSet structv0.1.0
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
Returns: the set
Methods
Length
pub func Length(self: &BitSet) -> uint
How many bits the set spans, set or not.
Returns: the length in bits
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.
| Name | Type | Description |
|---|---|---|
length | uint | the length in bits |
Returns: nothing, or why there was no room
Get
pub func Get(self: &BitSet, index: uint) -> bool
Whether bit index is set; false for one past the length.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Returns: whether it is set
Set
pub func Set(
self: &var BitSet,
index: uint
) -> ! CollectionError
Sets bit index, growing the set to span it.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Returns: nothing, or why there was no room to grow
Reset
pub func Reset(self: &var BitSet, index: uint)
Unsets bit index. A bit past the length is already unset.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Toggle
pub func Toggle(
self: &var BitSet,
index: uint
) -> ! CollectionError
Flips bit index, growing the set to span it.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Returns: nothing, or why there was no room to grow
Count
pub func Count(self: &BitSet) -> uint
How many bits are set.
Returns: the count
IsEmpty
pub func IsEmpty(self: &BitSet) -> bool
Whether no bit is set.
Returns: whether the set is empty
Clear
pub func Clear(self: &var BitSet)
Unsets every bit, keeping the length.
NextSet
pub func NextSet(self: &BitSet, from: uint) -> uint?
The lowest set bit at or after from, which walks the set in order.
| Name | Type | Description |
|---|---|---|
from | uint | where to start looking |
Returns: the bit, or none when no bit there or after is set
UnionWith
pub func UnionWith(
self: &var BitSet,
other: &BitSet
) -> ! CollectionError
Sets every bit that is set in other, growing to span it.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
Returns: nothing, or why there was no room to grow
IntersectWith
pub func IntersectWith(self: &var BitSet, other: &BitSet)
Unsets every bit that is not set in other.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
DifferenceWith
pub func DifferenceWith(self: &var BitSet, other: &BitSet)
Unsets every bit that is set in other.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
Equals
pub func Equals(self: &BitSet, other: &BitSet) -> bool
Whether the same bits are set in both, whatever their lengths.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
Returns: whether they hold the same members