Documentation ¶
Overview ¶
Package set implements Set types for Go.
Index ¶
- type MapSet
- func (s *MapSet[T]) Add(elem T) bool
- func (s *MapSet[T]) Cardinality() int
- func (s *MapSet[T]) Clone() Set[T]
- func (s *MapSet[T]) Contains(elem T) bool
- func (s *MapSet[T]) Difference(s2 Set[T]) Set[T]
- func (s *MapSet[T]) Elements() []T
- func (s *MapSet[T]) Equal(s2 Set[T]) bool
- func (s *MapSet[T]) Intersection(s2 Set[T]) Set[T]
- func (s *MapSet[T]) IsEmpty() bool
- func (s *MapSet[T]) IsProperSubset(s2 Set[T]) bool
- func (s *MapSet[T]) IsSubset(s2 Set[T]) bool
- func (s *MapSet[T]) Remove(elem T) bool
- func (s *MapSet[T]) String() string
- func (s *MapSet[T]) SymDifference(s2 Set[T]) Set[T]
- func (s *MapSet[T]) Union(s2 Set[T]) Set[T]
- type Set
- type TreeSet
- func (s *TreeSet[T]) Add(elem T) bool
- func (s *TreeSet[T]) Cardinality() int
- func (s *TreeSet[T]) Clone() Set[T]
- func (s *TreeSet[T]) Contains(elem T) bool
- func (s *TreeSet[T]) Difference(s2 Set[T]) Set[T]
- func (s *TreeSet[T]) Elements() []T
- func (s *TreeSet[T]) Equal(s2 Set[T]) bool
- func (s *TreeSet[T]) Intersection(s2 Set[T]) Set[T]
- func (s *TreeSet[T]) IsEmpty() bool
- func (s *TreeSet[T]) IsProperSubset(s2 Set[T]) bool
- func (s *TreeSet[T]) IsSubset(s2 Set[T]) bool
- func (s *TreeSet[T]) Remove(elem T) bool
- func (s *TreeSet[T]) String() string
- func (s *TreeSet[T]) SymDifference(s2 Set[T]) Set[T]
- func (s *TreeSet[T]) Union(s2 Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapSet ¶ added in v0.3.0
type MapSet[T comparable] struct { // contains filtered or unexported fields }
MapSet type that implements the Set interface. It uses a Go map to store the elements.
func NewMapSet ¶ added in v0.3.0
func NewMapSet[T comparable](elems ...T) *MapSet[T]
NewMapSet returns a new MapSet with the given elements.
func (*MapSet[T]) Add ¶ added in v0.3.0
Add adds an element to the Set. Returns true if it was added, false if it already was in the set.
func (*MapSet[T]) Cardinality ¶ added in v0.3.0
Cardinality returns the number of elements in the Set.
func (*MapSet[T]) Difference ¶ added in v0.3.0
Difference returns a new Set which is the set difference of s and s2.
func (*MapSet[T]) Elements ¶ added in v0.3.0
func (s *MapSet[T]) Elements() []T
Elements returns a slice with all elements of the Set.
func (*MapSet[T]) Intersection ¶ added in v0.3.0
Intersection returns a new Set which is the intersection of s and s2.
func (*MapSet[T]) IsProperSubset ¶ added in v0.3.0
IsProperSubset returns true if s is a proper subset of s2.
func (*MapSet[T]) Remove ¶ added in v0.3.0
Remove removes an element from the Set. Returns true if it was in the set, false otherwise.
func (*MapSet[T]) SymDifference ¶ added in v0.3.0
SymDifference returns a new Set which is the symmetric difference of s and s2.
type Set ¶
type Set[T any] interface { // Contains reports whether the element is in the Set. Contains(elem T) bool // Add adds an element to the Set. // Returns true if it was added, false if it already was in the set. Add(elem T) bool // Remove removes an element from the Set. // Returns true if it was in the set, false otherwise. Remove(elem T) bool // IsEmpty returns true if Set is an empty set. IsEmpty() bool // Cardinality returns the number of elements in the Set. Cardinality() int // Union returns a new Set which is the union of the Set and s2. Union(s2 Set[T]) Set[T] // Intersection returns a new Set which is the intersection of the Set and s2. Intersection(s2 Set[T]) Set[T] // Difference returns a new Set which is the set difference of the Set and s2. Difference(s2 Set[T]) Set[T] // SymDifference returns a new Set which is the symmetric difference of the Set and s2. SymDifference(s2 Set[T]) Set[T] // IsSubset returns true if the Set is a subset of s2. IsSubset(s2 Set[T]) bool // IsProperSubset returns true if the Set is a proper subset of s2. IsProperSubset(s2 Set[T]) bool // Equal returns true if the Set and s2 contain the same elements. Equal(s2 Set[T]) bool // Clone clones the Set. Clone() Set[T] // Elements returns a slice with all elements of the Set. Elements() []T // String returns a string representation of the Set. String() string }
type TreeSet ¶ added in v0.3.0
type TreeSet[T any] struct { // contains filtered or unexported fields }
TreeSet type that implements the Set interface. It uses an AVL tree to store the elements.
func NewTreeSet ¶ added in v0.3.0
NewTreeSet returns a new TreeSet with the given elements.
func NewTreeSetFunc ¶ added in v0.3.0
NewTreeSetFunc returns a new TreeSet with the given elements. Function cmp is used to compare two elements. It returns 0 if a == b, -1 if a < b, and 1 if a > b.
func (*TreeSet[T]) Add ¶ added in v0.3.0
Add adds an element to the Set. Returns true if it was added, false if it already was in the set.
func (*TreeSet[T]) Cardinality ¶ added in v0.3.0
Cardinality returns the number of elements in the Set.
func (*TreeSet[T]) Difference ¶ added in v0.3.0
Difference returns a new Set which is the set difference of s and s2.
func (*TreeSet[T]) Elements ¶ added in v0.3.0
func (s *TreeSet[T]) Elements() []T
Elements returns a slice with all elements of the Set.
func (*TreeSet[T]) Equal ¶ added in v0.3.0
Equal returns true if s and s2 contain the same elements.
func (*TreeSet[T]) Intersection ¶ added in v0.3.0
Intersection returns a new Set which is the intersection of s and s2.
func (*TreeSet[T]) IsProperSubset ¶ added in v0.3.0
IsProperSubset returns true if s is a proper subset of s2.
func (*TreeSet[T]) Remove ¶ added in v0.3.0
Remove removes an element from the Set. Returns true if it was in the set, false otherwise.
func (*TreeSet[T]) SymDifference ¶ added in v0.3.0
SymDifference returns a new Set which is the symmetric difference of s and s2.