Documentation
¶
Overview ¶
Package bitarray implements a bit array.
The least significant bit is at index 0. In the string representation used by Parse, MustParse, and BitArray.String it is the rightmost digit. The byte slice used by FromBytes and BitArray.ToBytes is in big-endian order.
Index ¶
- type BitArray
- func (ba *BitArray) And(other *BitArray)
- func (ba *BitArray) AndNot(other *BitArray)
- func (ba *BitArray) Clear()
- func (ba *BitArray) Count() int
- func (ba *BitArray) Equal(other *BitArray) bool
- func (ba *BitArray) Get(idx int) bool
- func (ba *BitArray) LeadingZeros() int
- func (ba *BitArray) MarshalBinary() ([]byte, error)
- func (ba *BitArray) Not()
- func (ba *BitArray) Or(other *BitArray)
- func (ba *BitArray) Reverse()
- func (ba *BitArray) Rotate(n int)
- func (ba *BitArray) Set(idx int)
- func (ba *BitArray) SetAll()
- func (ba *BitArray) Shift(n int)
- func (ba *BitArray) Size() int
- func (ba *BitArray) String() string
- func (ba *BitArray) ToBytes() []byte
- func (ba *BitArray) Toggle(idx int) bool
- func (ba *BitArray) TrailingZeros() int
- func (ba *BitArray) UnmarshalBinary(data []byte) error
- func (ba *BitArray) Unset(idx int)
- func (ba *BitArray) Xor(other *BitArray)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BitArray ¶
type BitArray struct {
// contains filtered or unexported fields
}
BitArray type.
func FromBytes ¶ added in v0.4.0
FromBytes creates a new BitArray from the byte slice. Panics if len(bytes) == 0.
func MustParse ¶
MustParse creates a new BitArray by parsing the given string. Space characters are ignored. Panics if one of the characters in the string is not space, 0, or 1.
func New ¶
New creates a new BitArray with size bits and the bits at the given indexes set to 1. Panics if size <= 0 or one of the indexes is out of range.
func Parse ¶
Parse creates a new BitArray by parsing the given string. Space characters are ignored. Returns an error if one of the characters in the string is not space, 0, or 1.
func (*BitArray) LeadingZeros ¶
LeadingZeros returns the number of leading unset bits.
func (*BitArray) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*BitArray) Reverse ¶ added in v0.5.0
func (ba *BitArray) Reverse()
Reverse reverses the bit order
func (*BitArray) Rotate ¶
Rotate rotates the bit array by |n| bits. If n > 0 to the left, if n < 0 to the right.
func (*BitArray) Shift ¶
Shift shifts the bit array by |n| bits. If n > 0 to the left, if n < 0 to the right.
func (*BitArray) Toggle ¶ added in v0.3.0
Toggle toggles the state of the bit at index idx and reports whether it is set after being toggled.
func (*BitArray) TrailingZeros ¶
TrailingZeros returns the number of trailing unset bits.
func (*BitArray) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.