Documentation
¶
Index ¶
- Constants
- func ErrInvalidRange[BitStorage types.Unsigned, Value types.Integer](minVal, maxVal Value) error
- func ErrRangeOutOfBounds[Value types.Integer](minVal, maxVal Value) error
- func ErrValueOutOfBounds[Value types.Integer](value Value) error
- func ErrValuesMaskOutOfBounds[BitStorage types.Unsigned](valuesMask BitStorage) error
- func FilterOutRange[BitStorage types.Unsigned, Value types.Integer](allowed Seq[BitStorage], minVal, maxVal Value) (Seq[BitStorage], RangeState)
- func LeftmostBitPosIn[BitStorage types.Unsigned]() int
- type RangeState
- type Seq
- func FilterOut[BitStorage types.Unsigned, Value types.Integer](allowed Seq[BitStorage], value Value) Seq[BitStorage]
- func New[BitStorage types.Unsigned](bs BitStorage) Seq[BitStorage]
- func NewFromRange[BitStorage types.Unsigned, Value types.Integer](minVal, maxVal Value) Seq[BitStorage]
- func NewFromRangeOrError[BitStorage types.Unsigned, Value types.Integer](minVal, maxVal Value) (Seq[BitStorage], error)
- func NewFromValue[BitStorage types.Unsigned, Value types.Integer](value Value) Seq[BitStorage]
- func (r Seq[BitStorage]) And(other Seq[BitStorage]) Seq[BitStorage]
- func (r Seq[BitStorage]) IsZero() bool
- func (r Seq[BitStorage]) LeftShift(n uint) Seq[BitStorage]
- func (r Seq[BitStorage]) LeftmostOnePos() int
- func (r Seq[BitStorage]) Not() Seq[BitStorage]
- func (r Seq[BitStorage]) Or(other Seq[BitStorage]) Seq[BitStorage]
- func (r Seq[BitStorage]) OrWithOverlapCheck(other Seq[BitStorage]) (concatenated Seq[BitStorage], overlapped bool)
- func (r Seq[BitStorage]) RightShift(n uint) Seq[BitStorage]
- func (r Seq[BitStorage]) RightmostOnePos() int
- func (r Seq[BitStorage]) Value() BitStorage
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ErrInvalidRange ¶
func ErrRangeOutOfBounds ¶
func ErrValueOutOfBounds ¶
func FilterOutRange ¶
func FilterOutRange[ BitStorage types.Unsigned, Value types.Integer, ]( allowed Seq[BitStorage], minVal, maxVal Value, ) (Seq[BitStorage], RangeState)
FilterOutRange transforms the given range of values to Seq; see NewFromRange. The given allowed bits are used as a clamp to filter out unfit values and to say via RangeState whether the given range is invalid or out of bounds.
func LeftmostBitPosIn ¶
LeftmostBitPosIn returns the leftmost bit position in BitStorage.
E.g., it is 7 for uint8, 15 for uint16, 31 for uint32, 63 for uint64.
Types ¶
type RangeState ¶
type RangeState struct {
IsInvalid, IsOutOfBounds bool
}
type Seq ¶
Seq is a bit sequence stored in the value of the given BitStorage type.
NOTE: we cannot use a type parameter as right-hand side in type declaration so here is a trick: wrap it in the single-element array.
func FilterOut ¶
func FilterOut[ BitStorage types.Unsigned, Value types.Integer, ](allowed Seq[BitStorage], value Value) Seq[BitStorage]
FilterOut transforms the given value to Seq; see NewFromValue. The given allowed bits are used as a clamp to filter out unfit values.
func NewFromRange ¶
func NewFromRange[ BitStorage types.Unsigned, Value types.Integer, ](minVal, maxVal Value) Seq[BitStorage]
NewFromRange takes two given values as [minVal; maxVal] range and transforms them into Seq.
E.g., [0; 0] and [1; 5] for uint8 BitStorage transform into 0b0000_0001 and 0b0011_1110 respectfully.
It returns a zero BitStorage if the range is invalid, that is:
- minVal or maxVal is negative;
- minVal is greater than maxVal;
- maxVal is greater than LeftmostBitPosIn[BitStorage]().
func NewFromRangeOrError ¶
func NewFromRangeOrError[ BitStorage types.Unsigned, Value types.Integer, ](minVal, maxVal Value) (Seq[BitStorage], error)
NewFromRangeOrError is the same as NewFromRange but returns an error if the range is invalid.
func NewFromValue ¶
NewFromValue takes the given value and transforms it into Seq.
The value is interpreted as a set bit position in BitStorage starting from the rightmost bit with position 0. If the value does not fit BitStorage positions range, that is, [0; LeftmostBitPosIn[BitStorage]()], then zero Seq will be returned.
func (Seq[BitStorage]) LeftShift ¶
LeftShift performs a bitwise left shift operation on the given Seq.
func (Seq[BitStorage]) LeftmostOnePos ¶
LeftmostOnePos returns the position the leftmost one bit in BitStorage, if any, otherwise, -1.
fmt.Println(bitmask.New[uint8](0b0010_0000).LeftmostOnePos() == 5) // true fmt.Println(bitmask.NewFromValue[uint8](5).LeftmostOnePos() == 5) // true fmt.Println(bitmask.NewFromValue[uint8](0).LeftmostOnePos() == -1) // true
func (Seq[BitStorage]) OrWithOverlapCheck ¶
func (r Seq[BitStorage]) OrWithOverlapCheck( other Seq[BitStorage], ) (concatenated Seq[BitStorage], overlapped bool)
OrWithOverlapCheck performs a bitwise OR operation on the given Seq's and says whether they overlap.
func (Seq[BitStorage]) RightShift ¶
RightShift performs a bitwise right shift operation on the given Seq.
func (Seq[BitStorage]) RightmostOnePos ¶
RightmostOnePos returns the position the rightmost one bit in BitStorage, if any, otherwise, AmountInUint64.
fmt.Println(bitmask.New[uint8](0b0000_0010).RightmostOnePos() == 1) // true fmt.Println(bitmask.NewFromValue[uint8](1).RightmostOnePos() == 1) // true fmt.Println(bitmask.NewFromValue[uint8](0).RightmostOnePos() == bitmask.AmountInUint64) // true