set

package
v1.0.0-maxwell Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

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 BitsFromBytes

func BitsFromBytes(bytes []byte) Bits

Inverse of Bits.Bytes()

func NewBits

func NewBits(bits ...int) Bits

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) Add

func (b Bits) Add(i int)

Add sets the [i]'th bit to 1

func (Bits) BitLen

func (b Bits) BitLen() int

BitLen returns the bit length of this bitset

func (Bits) Bytes

func (b Bits) Bytes() []byte

Returns the byte representation of this bitset

func (Bits) Clear

func (b Bits) Clear()

Clear empties out the bitset

func (Bits) Contains

func (b Bits) Contains(i int) bool

Contains returns true if the [i]'th bit is 1, and false otherwise

func (Bits) Difference

func (b Bits) Difference(other Bits)

Difference removes all the elements in [other] from this set

func (Bits) Intersection

func (b Bits) Intersection(other Bits)

Intersection performs the set intersection with another set This sets [b] to include only elements in both [b] and [other]

func (Bits) Len

func (b Bits) Len() int

Len returns the amount of 1's in the bitset

This is typically referred to as the "Hamming Weight" of a set of bits.

func (Bits) Remove

func (b Bits) Remove(i int)

Remove sets the [i]'th bit to 0

func (Bits) String

func (b Bits) String() string

String returns the hex representation of this bitset

func (Bits) Union

func (b Bits) Union(other Bits)

Union performs the set union with another set. This adds all elements in [other] to [b]

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) Add

func (b *Bits64) Add(i uint)

Add [i] to the set of ints

func (*Bits64) Clear

func (b *Bits64) Clear()

Clear removes all elements from this set

func (Bits64) Contains

func (b Bits64) Contains(i uint) bool

Contains returns true if [i] was previously added to this set

func (*Bits64) Difference

func (b *Bits64) Difference(s Bits64)

Difference removes all the elements in [s] from this set

func (*Bits64) Intersection

func (b *Bits64) Intersection(s Bits64)

Intersection takes the intersection of [s] with this set

func (Bits64) Len

func (b Bits64) Len() int

Len returns the number of elements in this set

func (*Bits64) Remove

func (b *Bits64) Remove(i uint)

Remove [i] from the set of ints

func (Bits64) String

func (b Bits64) String() string

func (*Bits64) Union

func (b *Bits64) Union(s Bits64)

Union adds all the elements in [s] to 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]) Clear

func (s *SampleableSet[T]) Clear()

Clear empties this set

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 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

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[_]) Clear

func (s *Set[_]) Clear()

Clear empties this set

func (*Set[T]) Contains

func (s *Set[T]) Contains(elt T) bool

Contains returns true iff the set contains this element.

func (*Set[T]) Difference

func (s *Set[T]) Difference(set Set[T])

Difference removes all the elements in set from [s].

func (Set[T]) Equals

func (s Set[T]) Equals(other Set[T]) bool

Equals returns true if the sets contain the same elements

func (Set[_]) Len

func (s Set[_]) Len() int

Len returns the number of elements in this set.

func (Set[T]) List

func (s Set[T]) List() []T

List converts this set into a list

func (Set[_]) MarshalJSON

func (s Set[_]) MarshalJSON() ([]byte, error)

func (*Set[T]) Overlaps

func (s *Set[T]) Overlaps(big Set[T]) bool

Overlaps returns true if the intersection of the set is non-empty

func (*Set[T]) Peek

func (s *Set[T]) Peek() (T, bool)

Returns a random element. If the set is empty, returns false

func (*Set[T]) Pop

func (s *Set[T]) Pop() (T, bool)

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.

func (*Set[T]) Union

func (s *Set[T]) Union(set Set[T])

Union adds all the elements from the provided set to this set.

func (*Set[T]) UnmarshalJSON

func (s *Set[T]) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL