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) -> uint
How many bits the set spans, set or not.
Returns: the length in bits
Resize
pub func Resize(&var self, length: uint)
Spans length bits: new bits are unset, and bits past a shorter length are dropped.
| Name | Type | Description |
|---|---|---|
length | uint | the length in bits |
Get
pub func Get(&self, 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(&var self, index: uint)
Sets bit index, growing the set to span it.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Reset
pub func Reset(&var self, index: uint)
Unsets bit index. A bit past the length is already unset.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Toggle
pub func Toggle(&var self, index: uint)
Flips bit index, growing the set to span it.
| Name | Type | Description |
|---|---|---|
index | uint | the bit |
Count
pub func Count(&self) -> uint
How many bits are set.
Returns: the count
IsEmpty
pub func IsEmpty(&self) -> bool
Whether no bit is set.
Returns: whether the set is empty
Clear
pub func Clear(&var self)
Unsets every bit, keeping the length.
NextSet
pub func NextSet(&self, 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(&var self, other: &BitSet)
Sets every bit that is set in other, growing to span it.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
IntersectWith
pub func IntersectWith(&var self, other: &BitSet)
Unsets every bit that is not set in other.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
DifferenceWith
pub func DifferenceWith(&var self, other: &BitSet)
Unsets every bit that is set in other.
| Name | Type | Description |
|---|---|---|
other | &BitSet | the other set |
Equals
pub func Equals(&self, 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