Documentation ¶
Overview ¶
Package bitset provides Set, a compact and fast representation for a dense set of positive integer values.
Index ¶
- type Set
- func (s *Set) Add(i int)
- func (s *Set) AddRange(low, hi int)
- func (s *Set) Bytes() []byte
- func (s *Set) Cardinality() int
- func (s *Set) Copy() *Set
- func (s *Set) Equal(ss *Set) bool
- func (s *Set) FromBytes(data []byte)
- func (s *Set) Intersect(ss *Set)
- func (s *Set) Max() int
- func (s *Set) NextAfter(i int) int
- func (s *Set) Remove(i int)
- func (s *Set) RemoveRange(low, hi int)
- func (s *Set) String() string
- func (s *Set) Subtract(ss *Set)
- func (s *Set) SymmetricDifference(ss *Set)
- func (s *Set) Test(i int) bool
- func (s *Set) Union(ss *Set)
Examples ¶
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 represents a set of positive integers. Memory usage is proportional to the largest integer in the Set.
func (*Set) AddRange ¶
AddRange adds integers in the interval [low, hi) to the set. AddRange panics if low is less than zero.
func (*Set) Bytes ¶
Bytes returns the set as a bitarray. The most significant bit in each byte represents the smallest-index number.
Example ¶
s := new(Set) s.Add(0) s.Add(3) s.Add(8) s.Add(10) b := s.Bytes() fmt.Printf("%b %b", b[0], b[1])
Output: 10010000 10100000
func (*Set) Cardinality ¶
Cardinality returns the number of integers in s.
func (*Set) FromBytes ¶
FromBytes sets s to the value of data interpreted as a bitarray in the same format as produced by Bytes..
func (*Set) NextAfter ¶
NextAfter returns the smallest integer in s greater than or equal to i or -1 if no such integer exists.
Example ¶
NextAfter can be used to iterate over the elements of the set.
s := new(Set) s.Add(2) s.Add(42) s.Add(13) for i := s.NextAfter(0); i >= 0; i = s.NextAfter(i + 1) { fmt.Println(i) }
Output: 2 13 42
func (*Set) RemoveRange ¶
RemoveRange removes integers in the interval [low, hi) from the set.
func (*Set) String ¶
String returns a string representation of s.
Example ¶
s := new(Set) s.Add(2) s.Add(42) s.Add(13) fmt.Println(s)
Output: [2 13 42]
func (*Set) SymmetricDifference ¶
SymmetricDifference adds integers to s which are in ss but not in s, and removes integers in s that are also in ss.