Documentation
¶
Overview ¶
Package bitmask is an implementation of an arbitrary size sequence of bits with Go-like Slice method.
Index ¶
- func Copy(dst *BitMask, src *BitMask) uint
- type BitIterator
- type BitMask
- func (bm *BitMask) Clear(bitIndex uint)
- func (bm *BitMask) ClearAll()
- func (bm *BitMask) IsSet(bitIndex uint) bool
- func (bm *BitMask) Iterator() BitIterator
- func (bm *BitMask) Len() uint
- func (bm *BitMask) LenUint() int
- func (bm *BitMask) Set(bitIndex uint)
- func (bm *BitMask) SetAll()
- func (bm *BitMask) Slice(fromBit uint, toBit uint) *BitMask
- func (bm *BitMask) String() string
- func (bm *BitMask) Toggle(bitIndex uint)
- func (bm *BitMask) ToggleAll()
- func (bm *BitMask) Uint(index int) uint
- func (bm *BitMask) UintRaw(index int) uint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BitIterator ¶ added in v0.2.0
type BitIterator struct { // Atttempts to get the next item from the iterator. // If there're no more values left, ok will be false. Next func() (ok bool, isSet bool, index uint) // Resets iterator, so it can be reused Reset func() }
Stateful iterator. Example of usage:
it := bm.Iterator() for { ok, value, index := it.Next() if !ok { break; } // use the value }
type BitMask ¶
type BitMask struct {
// contains filtered or unexported fields
}
Represents a fixed-size array of 0/1 bits.
func NewFromUint ¶
Create a bitmask from uints, automatically reversing endianness, so that NewFromUint(1) produces the bitmask with the lowest (leftmost) bit set. Len() of the resulting bitmask will always be equal to len(values) * sizeof(uint).
func NewFromUintRaw ¶ added in v1.2.0
Create a bitmask from uints, without endianness reversal, more effective version of NewFromUint
func (*BitMask) ClearAll ¶ added in v0.2.0
func (bm *BitMask) ClearAll()
Clears all bits. Use in combination with Slice to clear the range of bits.
func (*BitMask) IsSet ¶
Checks, whether the bit by bitIndex is set or cleared. Returns true if bit is set, and false if it's cleared.
func (*BitMask) Iterator ¶
func (bm *BitMask) Iterator() BitIterator
Creates stateful iterator to iterate through all the bits. See BitIterator doc for an example. It is an equivalent of just calling IsSet for each bit of a BitMask.
func (*BitMask) Len ¶
Returns the legth of bitmask in bits. It will never be changed for the given receiver.
func (*BitMask) LenUint ¶ added in v1.2.0
Returns the legth of bitmask in uints. Result is always positive and multiple of size(uint), e.g.: 32, 64, 96, 128, ...
func (*BitMask) SetAll ¶ added in v0.2.0
func (bm *BitMask) SetAll()
Sets all bits to 1. Use in combination with Slice to set the range of bits.
func (*BitMask) Slice ¶
Effectively creates a new BitMask, without copying elements, just like regular slices work. As a side-effect, change to the sliced bitmask will be visible to original bitmask (and other way around), as well as to other "overlapping" slices. Selects a half-open range which includes the "from" bit, but excludes the "to" one.
func (*BitMask) String ¶ added in v0.2.0
Returns string representation of a bitmask in the form "[length]{bits}". For example: [4]{0100} It is O(1) operation and it will skip bits after some amount of them. Should not be parsed, format is not fixed.
func (*BitMask) ToggleAll ¶ added in v0.2.0
func (bm *BitMask) ToggleAll()
Reverses the value of all bits. Use in combination with Slice to reverse the range of bits.