Documentation ¶
Overview ¶
Package bitset contains the implementation of a set backed by a bit array.
Index ¶
- type Set
- func (s *Set) Add(e uint)
- func (b *Set) AsBits() string
- func (s *Set) Clone() *Set
- func (s *Set) Contains(e uint) bool
- func (s *Set) Difference(other *Set) *Set
- func (s *Set) Equal(other *Set) bool
- func (s *Set) Remove(e uint)
- func (s *Set) RemoveAll()
- func (s *Set) Size() int
- func (s *Set) Union(other *Set) *Set
- func (b *Set) Values() []uint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is an implementation of a set ADT backed by a bit array. It can store elements in the range [0..math.MaxUint64]. Default value represents an empty set and is ready to use.
func New ¶
New creates a new set with a hint that at least length bits are required. If length is 0, returns an empty set.
func (*Set) Contains ¶
Contains returns true if this set contains the specified element. Specifically, it returns true if the bit at index e is set to 1. If e is larger than [Set.Len] returns false.
func (*Set) Difference ¶
Difference returns the difference of two sets. Specifically, the bit in the resulting set is set to 1 if it is set to 1 in this set and set to 0 in other set.
func (*Set) Equal ¶
Equal returns true if the provided set and this set contain the same elements. Namely, the lengths of the sets can be different.
func (*Set) Remove ¶
Remove removes the element e from the set. Specifically, it sets the bit at index e to 0. If e is larger than [Set.Len] set is left unchanged.
func (*Set) RemoveAll ¶
func (s *Set) RemoveAll()
RemoveAll removes all the elements from the set. Specifically, it sets all the bits to 0.
func (*Set) Size ¶
Size returns the number of the elements in the set. Specifically, it returns the number of bits set to 1 in a bitset (population count).