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(elements ...T)
- func (s Set[T]) Clear()
- func (s Set[T]) Contains(element T) bool
- func (s Set[T]) Difference(other Set[T]) Set[T]
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[T]) Intersection(other Set[T]) Set[T]
- func (s Set[T]) Len() int
- func (s Set[T]) List() []T
- func (s Set[T]) MarshalJSON() ([]byte, error)
- func (s Set[T]) Overlaps(other Set[T]) bool
- func (s Set[T]) Peek() (T, bool)
- func (s Set[T]) Pop() (T, bool)
- func (s Set[T]) Remove(element T)
- func (s Set[T]) Union(other Set[T]) Set[T]
- func (s *Set[T]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bits ¶
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 ¶
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) Difference ¶
Difference removes all the elements in [other] from this set
func (Bits) Intersection ¶
Intersection performs the set intersection with another set This sets [b] to include only elements in both [b] and [other]
func (Bits) Len ¶
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 ¶
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) Difference ¶
Difference removes all the elements in [s] from this set
func (*Bits64) Intersection ¶
Intersection takes the intersection of [s] with this set
type SampleableSet ¶
type SampleableSet[T comparable] struct { // contains filtered or unexported fields }
SampleableSet is a set of elements that supports sampling.
func NewSampleableSet ¶
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 ¶
func OfSampleable[T comparable](elts ...T) SampleableSet[T]
OfSampleable returns a Set initialized with [elts]
func (*SampleableSet[T]) Add ¶
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]) Contains ¶
func (s SampleableSet[T]) Contains(e T) bool
Contains returns true iff the set contains this element.
func (*SampleableSet[T]) Difference ¶
func (s *SampleableSet[T]) Difference(set SampleableSet[T])
Difference removes all the elements in set from [s].
func (SampleableSet[T]) Equals ¶
func (s SampleableSet[T]) Equals(other SampleableSet[T]) bool
Equals returns true if the sets contain the same elements
func (SampleableSet[_]) Len ¶
func (s SampleableSet[_]) Len() int
Len returns the number of elements in this set.
func (SampleableSet[T]) List ¶
func (s SampleableSet[T]) List() []T
List converts this set into a list
func (*SampleableSet[_]) MarshalJSON ¶
func (s *SampleableSet[_]) MarshalJSON() ([]byte, error)
func (SampleableSet[T]) Overlaps ¶
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 ¶
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 ¶
func (s SampleableSet[T]) Sample(numToSample int) []T
func (*SampleableSet[T]) Union ¶
func (s *SampleableSet[T]) Union(set SampleableSet[T])
Union adds all the elements from the provided set to this set.
func (*SampleableSet[T]) UnmarshalJSON ¶
func (s *SampleableSet[T]) UnmarshalJSON(b []byte) error
type Set ¶
type Set[T comparable] map[T]struct{}
Set represents a set of unique elements
func NewSet ¶
func NewSet[T comparable](capacity ...int) Set[T]
NewSet creates a new empty set with optional initial capacity
func (Set[T]) Add ¶
func (s Set[T]) Add(elements ...T)
Add adds one or more elements to the set If the set is nil, this method will panic. Use NewSet() or Of() to create an initialized set.
func (Set[T]) Difference ¶
Difference returns a new set containing elements in s but not in other
func (Set[T]) Intersection ¶
Intersection returns a new set containing only elements in both sets
func (Set[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface Marshals the set as a JSON array of elements in sorted order
func (Set[T]) Peek ¶
Peek returns a random element from the set. If the set is empty, returns the zero value and false.
func (Set[T]) Pop ¶
Pop removes and returns an arbitrary element from the set Returns the element and true if the set was non-empty, otherwise returns zero value and false
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface Unmarshals a JSON array into a set, replacing existing contents