Documentation ¶
Overview ¶
bitset contains an efficient implementation of a set of unsigned numbers.
Index ¶
- type BitSet
- func (s *BitSet) Add(i int)
- func (s *BitSet) Clear()
- func (s *BitSet) Clone() *BitSet
- func (s1 *BitSet) Difference(s2 *BitSet)
- func (s1 *BitSet) Equal(s2 *BitSet) bool
- func (s *BitSet) Has(i int) bool
- func (s1 *BitSet) Intersection(s2 *BitSet)
- func (s1 *BitSet) IsDisjoint(s2 *BitSet) bool
- func (s1 *BitSet) IsSubset(s2 *BitSet) bool
- func (s1 *BitSet) IsSuperset(s2 *BitSet) bool
- func (s *BitSet) Iter() iter.Iterator[int]
- func (s *BitSet) Len() int
- func (s *BitSet) Remove(i int)
- func (s1 *BitSet) Union(s2 *BitSet)
- type Small
- func (s *Small) Add(i int)
- func (s *Small) Clear()
- func (s Small) Clone() Small
- func (s1 *Small) Difference(s2 Small)
- func (s1 Small) Equal(s2 Small) bool
- func (s Small) Has(i int) bool
- func (s1 *Small) Intersection(s2 Small)
- func (s1 Small) IsDisjoint(s2 Small) bool
- func (s1 Small) IsSubset(s2 Small) bool
- func (s1 Small) IsSuperset(s2 Small) bool
- func (s Small) Iter() iter.Iterator[int]
- func (s Small) Len() int
- func (s *Small) Remove(i int)
- func (s1 *Small) Union(s2 Small)
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 is a set of (almost) arbitrary-sized integers.
The zero value (`&BitSet{}`) is a BitSet containing no elements.
The representation uses big.Int to check whether a number is included in the set, so a map-based set may be a better use-case for sparse sets without any upper-bound.
Even tough most operations accept `int` as an argument, those functions will panic if the provided number is negative.
See also Small - a more efficient implementation if elements are known to be in range [0, 63] inclusive - and which can be used as a key in a map (by fulfilling the comparable protocol).
func (*BitSet) Clear ¶
func (s *BitSet) Clear()
Clear ensures that no numbers are present in the set.
func (*BitSet) Difference ¶
Difference ensures s1 does not contain any elements from s1.
func (*BitSet) Intersection ¶
Intersection ensures s1 only contains elements that are present in both s1 and s2.
func (*BitSet) IsDisjoint ¶
IsDisjoint returns true if s1 and s2 have no elements in common.
func (*BitSet) IsSuperset ¶
IsSuperset returns true if every element of s2 is also present in s1.
type Small ¶
type Small uint64
Small is a set of integers between 0 and 63 (inclusive), which also fulfills the `comparable` interface and can be used e.g. as a map key.
The zero value (`Small(0)`) is a set containing no elements.
The representation is a simple wrapper around uint64.
Trying to provide elements outside of the <0, 63> range is undefined behavior.
See also BitSet - an implementation for (almost) arbitrary sized elements.
func (*Small) Difference ¶
Difference ensures b1 does not contain any elements from b2.
func (*Small) Intersection ¶
Intersection ensures b1 only contains elements that are present in both b1 and b2.
func (Small) IsDisjoint ¶
IsDisjoint returns true if s1 and s2 have no elements in common.
func (Small) IsSuperset ¶
IsSuperset returns true if every element of s2 is also present in s1.
func (Small) Iter ¶
Iter returns an iterator over the elements in the set.
Any changes made during iteration are not reflected in the iterator; iteration is actually performed on a copy of the set.