Documentation ¶
Index ¶
- type Bits
- func (b Bits) Add(i int)
- func (b Bits) BitLen() int
- func (b Bits) Bytes() []byte
- func (b Bits) Clear()
- func (b Bits) Contains(i int) bool
- func (b Bits) Difference(other Bits)
- func (b Bits) Intersection(other Bits)
- func (b Bits) Len() int
- func (b Bits) Remove(i int)
- func (b Bits) String() string
- func (b Bits) Union(other Bits)
- type Bits64
- type SampleableSet
- func (s *SampleableSet[T]) Add(elements ...T)
- func (s *SampleableSet[T]) Clear()
- func (s SampleableSet[T]) Contains(e T) bool
- func (s *SampleableSet[T]) Difference(set SampleableSet[T])
- func (s SampleableSet[T]) Equals(other SampleableSet[T]) bool
- func (s SampleableSet[_]) Len() int
- func (s SampleableSet[T]) List() []T
- func (s *SampleableSet[_]) MarshalJSON() ([]byte, error)
- func (s SampleableSet[T]) Overlaps(big SampleableSet[T]) bool
- func (s *SampleableSet[T]) Remove(elements ...T)
- func (s SampleableSet[T]) Sample(numToSample int) []T
- func (s *SampleableSet[T]) Union(set SampleableSet[T])
- func (s *SampleableSet[T]) UnmarshalJSON(b []byte) error
- type Set
- func (s *Set[T]) Add(elts ...T)
- func (s Set[T]) CappedList(size int) []T
- func (s *Set[_]) Clear()
- func (s *Set[T]) Contains(elt T) bool
- func (s *Set[T]) Difference(set Set[T])
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[_]) Len() int
- func (s Set[T]) List() []T
- func (s Set[_]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) Overlaps(big Set[T]) bool
- func (s *Set[T]) Peek() (T, bool)
- func (s *Set[T]) Pop() (T, bool)
- func (s *Set[T]) Remove(elts ...T)
- func (s *Set[T]) Union(set Set[T])
- func (s *Set[T]) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bits ¶ added in v1.9.5
type Bits struct {
// contains filtered or unexported fields
}
Bits is a bit-set backed by a big.Int Holds values ranging from [0, INT_MAX] (arch-dependent) Trying to use negative values will result in a panic. This implementation is NOT thread-safe.
func NewBits ¶ added in v1.9.5
NewBits returns a new instance of Bits with bits set to 1.
Invariants: 1. Negative bits will cause a panic. 2. Duplicate bits are allowed but will cause a no-op.
func (Bits) Contains ¶ added in v1.9.5
Contains returns true if the [i]'th bit is 1, and false otherwise
func (Bits) Difference ¶ added in v1.9.5
Difference removes all the elements in [other] from this set
func (Bits) Intersection ¶ added in v1.9.5
Intersection performs the set intersection with another set This sets [b] to include only elements in both [b] and [other]
func (Bits) Len ¶ added in v1.9.5
Len returns the amount of 1's in the bitset
This is typically referred to as the "Hamming Weight" of a set of bits.
type Bits64 ¶ added in v1.9.5
type Bits64 uint64
Bits64 is a set that can contain uints in the range [0, 64). All functions are O(1). The zero value is the empty set.
func (*Bits64) Clear ¶ added in v1.9.5
func (b *Bits64) Clear()
Clear removes all elements from this set
func (Bits64) Contains ¶ added in v1.9.5
Contains returns true if [i] was previously added to this set
func (*Bits64) Difference ¶ added in v1.9.5
Difference removes all the elements in [s] from this set
func (*Bits64) Intersection ¶ added in v1.9.5
Intersection takes the intersection of [s] with this set
type SampleableSet ¶ added in v1.10.6
type SampleableSet[T comparable] struct { // contains filtered or unexported fields }
SampleableSet is a set of elements that supports sampling.
func NewSampleableSet ¶ added in v1.10.6
func NewSampleableSet[T comparable](size int) SampleableSet[T]
Return a new sampleable set with initial capacity [size]. More or less than [size] elements can be added to this set. Using NewSampleableSet() rather than SampleableSet[T]{} is just an optimization that can be used if you know how many elements will be put in this set.
func OfSampleable ¶ added in v1.10.10
func OfSampleable[T comparable](elts ...T) SampleableSet[T]
OfSampleable returns a Set initialized with [elts]
func (*SampleableSet[T]) Add ¶ added in v1.10.6
func (s *SampleableSet[T]) Add(elements ...T)
Add all the elements to this set. If the element is already in the set, nothing happens.
func (*SampleableSet[T]) Clear ¶ added in v1.10.6
func (s *SampleableSet[T]) Clear()
Clear empties this set
func (SampleableSet[T]) Contains ¶ added in v1.10.6
func (s SampleableSet[T]) Contains(e T) bool
Contains returns true iff the set contains this element.
func (*SampleableSet[T]) Difference ¶ added in v1.10.6
func (s *SampleableSet[T]) Difference(set SampleableSet[T])
Difference removes all the elements in set from [s].
func (SampleableSet[T]) Equals ¶ added in v1.10.6
func (s SampleableSet[T]) Equals(other SampleableSet[T]) bool
Equals returns true if the sets contain the same elements
func (SampleableSet[_]) Len ¶ added in v1.10.6
func (s SampleableSet[_]) Len() int
Len returns the number of elements in this set.
func (SampleableSet[T]) List ¶ added in v1.10.6
func (s SampleableSet[T]) List() []T
List converts this set into a list
func (*SampleableSet[_]) MarshalJSON ¶ added in v1.10.6
func (s *SampleableSet[_]) MarshalJSON() ([]byte, error)
func (SampleableSet[T]) Overlaps ¶ added in v1.10.6
func (s SampleableSet[T]) Overlaps(big SampleableSet[T]) bool
Overlaps returns true if the intersection of the set is non-empty
func (*SampleableSet[T]) Remove ¶ added in v1.10.6
func (s *SampleableSet[T]) Remove(elements ...T)
Remove all the given elements from this set. If an element isn't in the set, it's ignored.
func (SampleableSet[T]) Sample ¶ added in v1.10.6
func (s SampleableSet[T]) Sample(numToSample int) []T
func (*SampleableSet[T]) Union ¶ added in v1.10.6
func (s *SampleableSet[T]) Union(set SampleableSet[T])
Union adds all the elements from the provided set to this set.
func (*SampleableSet[T]) UnmarshalJSON ¶ added in v1.10.6
func (s *SampleableSet[T]) UnmarshalJSON(b []byte) error
type Set ¶
type Set[T comparable] map[T]struct{}
Set is a set of elements.
func NewSet ¶
func NewSet[T comparable](size int) Set[T]
Return a new set with initial capacity [size]. More or less than [size] elements can be added to this set. Using NewSet() rather than Set[T]{} is just an optimization that can be used if you know how many elements will be put in this set.
func Of ¶ added in v1.10.8
func Of[T comparable](elts ...T) Set[T]
Of returns a Set initialized with [elts]
func (*Set[T]) Add ¶
func (s *Set[T]) Add(elts ...T)
Add all the elements to this set. If the element is already in the set, nothing happens.
func (Set[T]) CappedList ¶
CappedList returns a list of length at most [size]. Size should be >= 0. If size < 0, returns nil.
func (*Set[T]) Difference ¶
Difference removes all the elements in set from [s].
func (Set[_]) MarshalJSON ¶
func (*Set[T]) Pop ¶
Removes and returns an element. If the set is empty, does nothing and returns false.
func (*Set[T]) Remove ¶
func (s *Set[T]) Remove(elts ...T)
Remove all the given elements from this set. If an element isn't in the set, it's ignored.