Documentation ¶
Overview ¶
Package bitset implements an append only bit array.
To create a Bitset and append some bits:
// Bitset Contents b := bitset.New() // {} b.AppendBools(true, true, false) // {1, 1, 0} b.AppendBools(true) // {1, 1, 0, 1} b.AppendValue(0x02, 4) // {1, 1, 0, 1, 0, 0, 1, 0}
To read values:
len := b.Len() // 8 v := b.At(0) // 1 v = b.At(1) // 1 v = b.At(2) // 0 v = b.At(8) // 0
Index ¶
- type Bitset
- func (b *Bitset) Append(other *Bitset)
- func (b *Bitset) AppendBools(bits ...bool)
- func (b *Bitset) AppendByte(value byte, numBits int)
- func (b *Bitset) AppendBytes(data []byte)
- func (b *Bitset) AppendNumBools(num int, value bool)
- func (b *Bitset) AppendUint32(value uint32, numBits int)
- func (b *Bitset) At(index int) bool
- func (b *Bitset) Bits() []bool
- func (b *Bitset) ByteAt(index int) byte
- func (b *Bitset) Equals(other *Bitset) bool
- func (b *Bitset) Len() int
- func (b *Bitset) String() string
- func (b *Bitset) Substr(start int, end int) *Bitset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitset ¶
type Bitset struct {
// contains filtered or unexported fields
}
Bitset stores an array of bits.
func NewFromBase2String ¶
NewFromBase2String constructs and returns a Bitset from a string. The string consists of '1', '0' or ' ' characters, e.g. "1010 0101". The '1' and '0' characters represent true/false bits respectively, and ' ' characters are ignored.
The function panics if the input string contains other characters.
func (*Bitset) AppendBools ¶
AppendBools appends bits to the Bitset.
func (*Bitset) AppendByte ¶
AppendByte appends the numBits least significant bits from value.
func (*Bitset) AppendBytes ¶
AppendBytes appends a list of whole bytes.
func (*Bitset) AppendNumBools ¶
AppendNumBools appends num bits of value value.
func (*Bitset) AppendUint32 ¶
AppendUint32 appends the numBits least significant bits from value.