Documentation
¶
Index ¶
- func MustNew[BS BitSet[B, V, BT], B, V constraints.Unsigned, BT BoundaryTrait[V]](values ...V) BS
- func New[BS BitSet[B, V, BT], B, V constraints.Unsigned, BT BoundaryTrait[V]](values ...V) (BS, error)
- type BitSet
- func (bs BitSet[B, V, BT]) Has(value V) bool
- func (bs *BitSet[B, V, BT]) MustMutSet(value V)
- func (bs *BitSet[B, V, BT]) MustMutUnset(value V)
- func (bs BitSet[B, V, BT]) MustSet(value V) BitSet[B, V, BT]
- func (bs BitSet[B, V, BT]) MustUnset(value V) BitSet[B, V, BT]
- func (bs *BitSet[B, V, BT]) MutSet(value V) error
- func (bs *BitSet[B, V, BT]) MutUnset(value V) error
- func (bs *BitSet[B, V, BT]) NonStrictMutSet(value V)
- func (bs *BitSet[B, V, BT]) NonStrictMutUnset(value V)
- func (bs BitSet[B, V, BT]) NonStrictSet(value V) BitSet[B, V, BT]
- func (bs BitSet[B, V, BT]) NonStrictUnset(value V) BitSet[B, V, BT]
- func (bs BitSet[B, V, BT]) Set(value V) (BitSet[B, V, BT], error)
- func (bs BitSet[B, V, BT]) Unset(value V) (BitSet[B, V, BT], error)
- type BoundaryTrait
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustNew ¶
func MustNew[ BS BitSet[B, V, BT], B, V constraints.Unsigned, BT BoundaryTrait[V], ](values ...V) BS
MustNew is the same as New but panics on errors.
func New ¶
func New[ BS BitSet[B, V, BT], B, V constraints.Unsigned, BT BoundaryTrait[V], ](values ...V) (BS, error)
New creates a new BitSet.
It returns an error if the B, V, and BT types are not compatible, that is:
- boundaries is a correct range, i.e., (BT{}).Min() <= (BT{}).Max();
- possible set range [0; <bits in B> - 1] must include boundaries [(BT{}).Min(); (BT{}).Max()].
Types ¶
type BitSet ¶ added in v0.2.0
type BitSet[ B, V constraints.Unsigned, BT BoundaryTrait[V], ] struct { // contains filtered or unexported fields }
BitSet is a set that implemented on unsafe.Sizeof(B(0)) bytes and can contain values in the range from (BT{}).Min() to (BT{}).Max() inclusive.
All operations on the set have constant time complexity.
Use the Has method to check whether the given value is in the set.
The *Set and *Unset methods return a new set and error in case of exceeding the range. But they also have Must* and NonStrict* versions to panic or do nothing in case of the error. To change the current set, use *Mut* methods.
BitSet must be created via the New or MustNew functions, otherwise, it will panic on all the operations.
func (*BitSet[B, V, BT]) MustMutSet ¶ added in v0.2.0
func (bs *BitSet[B, V, BT]) MustMutSet(value V)
MustMutSet sets the given value in BitSet or panics if the value is out of range.
func (*BitSet[B, V, BT]) MustMutUnset ¶ added in v0.2.0
func (bs *BitSet[B, V, BT]) MustMutUnset(value V)
MustMutUnset unsets the given value in BitSet or panics if the value is out of range.
func (BitSet[B, V, BT]) MustSet ¶ added in v0.2.0
MustSet sets the given value in a new copy of BitSet or panics if the value is out of range.
func (BitSet[B, V, BT]) MustUnset ¶ added in v0.2.0
MustUnset unsets the given value in a new copy of BitSet or panics if the value is out of range.
func (*BitSet[B, V, BT]) MutSet ¶ added in v0.2.0
MutSet sets the given value in BitSet. It returns an error if the value is out of range.
func (*BitSet[B, V, BT]) MutUnset ¶ added in v0.2.0
MutUnset unsets the given value in BitSet. It returns an error if the value is out of range.
func (*BitSet[B, V, BT]) NonStrictMutSet ¶ added in v0.2.0
func (bs *BitSet[B, V, BT]) NonStrictMutSet(value V)
NonStrictMutSet sets the given value in BitSet. It ignores if the value is out of range.
func (*BitSet[B, V, BT]) NonStrictMutUnset ¶ added in v0.2.0
func (bs *BitSet[B, V, BT]) NonStrictMutUnset(value V)
NonStrictMutUnset unsets the given value in BitSet. It ignores if the value is out of range.
func (BitSet[B, V, BT]) NonStrictSet ¶ added in v0.2.0
NonStrictSet sets the given value in a new copy of BitSet. It ignores if the value is out of range.
func (BitSet[B, V, BT]) NonStrictUnset ¶ added in v0.2.0
NonStrictUnset unsets the given value in a new copy of BitSet. It ignores if the value is out of range.
type BoundaryTrait ¶
type BoundaryTrait[V constraints.Unsigned] interface { ~struct{} // Min returns the minimum allowed value. // // Prefer to return a constant value. Min() V // Max returns the maximum allowed value. // // Prefer to return a constant value. Max() V }
BoundaryTrait is a trait that defines the range from [BoundaryTrait.Min] to [BoundaryTrait.Max].