Documentation
¶
Overview ¶
Package set defines a Set type that holds a set of elements.
Package set defines a Set type that holds a set of elements.
Example ¶
// Create a new set.
s := NewSet[int]()
s.Add(1)
s.AddSet(OfSet(2, 3))
// Iterate through list and print its contents.
for i := 1; i < 5; i++ {
fmt.Println(s.Contains(i))
}
Output: true true true false
Index ¶
- type Set
- func (s Set[E]) Add(v ...E)
- func (s Set[E]) AddSet(s2 Set[E])
- func (s *Set[E]) Clear()
- func (s Set[E]) Clone() Set[E]
- func (s Set[E]) Contains(v E) bool
- func (s Set[E]) ContainsAll(s2 Set[E]) bool
- func (s Set[E]) ContainsAny(s2 Set[E]) bool
- func (s Set[E]) Do(f func(E) bool)
- func (s Set[E]) Equal(s2 Set[E]) bool
- func (s Set[E]) Filter(keep func(E) bool)
- func (s Set[E]) Len() int
- func (s Set[E]) Remove(v ...E)
- func (s Set[E]) RemoveSet(s2 Set[E])
- func (s Set[E]) Values() []E
- type SortedSet
- func DifferenceSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
- func IntersectionSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
- func NewSortedSet[E comparable](capability int) *SortedSet[E]
- func OfSortedSet[E comparable](v ...E) *SortedSet[E]
- func UnionSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
- func (s *SortedSet[E]) Add(v ...E)
- func (s *SortedSet[E]) AddSet(s2 *SortedSet[E])
- func (s *SortedSet[E]) Clear()
- func (s *SortedSet[E]) Clone() *SortedSet[E]
- func (s *SortedSet[E]) Contains(v E) bool
- func (s *SortedSet[E]) ContainsAll(s2 *SortedSet[E]) bool
- func (s *SortedSet[E]) ContainsAny(s2 *SortedSet[E]) bool
- func (s *SortedSet[E]) Do(f func(E) bool)
- func (s *SortedSet[E]) Equal(s2 *SortedSet[E]) bool
- func (s *SortedSet[E]) Filter(keep func(E) bool)
- func (s *SortedSet[E]) Len() int
- func (s *SortedSet[E]) Newest() (E, bool)
- func (s *SortedSet[E]) Oldest() (E, bool)
- func (s *SortedSet[E]) Remove(v ...E)
- func (s *SortedSet[E]) RemoveSet(s2 *SortedSet[E])
- func (s *SortedSet[E]) Values() []E
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[E comparable] map[E]struct{}
Set is a set of elements of some comparable type. Sets are implemented using maps, and have similar performance characteristics. Like maps, Sets are reference types. That is, for Sets s1 = s2 will leave s1 and s2 pointing to the same set of elements: changes to s1 will be reflected in s2 and vice-versa.
func Difference ¶
func Difference[E comparable](s1, s2 Set[E]) Set[E]
Difference constructs a new set containing the elements of s1 that are not present in s2.
func Intersection ¶
func Intersection[E comparable](s1, s2 Set[E]) Set[E]
Intersection constructs a new set containing the intersection of s1 and s2.
func OfSet ¶
func OfSet[E comparable](v ...E) Set[E]
OfSet returns a new set containing the listed elements.
func Union ¶
func Union[E comparable](s1, s2 Set[E]) Set[E]
Union constructs a new set containing the union of s1 and s2.
func (*Set[E]) Clear ¶
func (s *Set[E]) Clear()
Clear removes all elements from s, leaving it empty.
func (Set[E]) Clone ¶
Clone returns a copy of s. The elements are copied using assignment, so this is a shallow clone.
func (Set[E]) ContainsAll ¶
ContainsAll reports whether all of the elements in s2 are in s.
func (Set[E]) ContainsAny ¶
ContainsAny reports whether any of the elements in s2 are in s.
func (Set[E]) Do ¶
Do calls f on every Eent in the set s, stopping if f returns false. f should not change s. f will be called on values in an indeterminate order.
func (Set[E]) Remove ¶
func (s Set[E]) Remove(v ...E)
Remove removes elements from a set. elements that are not present are ignored.
type SortedSet ¶
type SortedSet[E comparable] maps.OrderedMap[E, struct{}]
Set is a set of elements of some comparable type in insert order.
func DifferenceSortedSet ¶
func DifferenceSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
DifferenceSortedSet constructs a new set containing the elements of s1 that are not present in s2.
func IntersectionSortedSet ¶
func IntersectionSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
IntersectionSortedSet constructs a new set containing the intersection of s1 and s2.
func NewSortedSet ¶
func NewSortedSet[E comparable](capability int) *SortedSet[E]
NewSortedSet returns a new SortedSet.
func OfSortedSet ¶
func OfSortedSet[E comparable](v ...E) *SortedSet[E]
OfSortedSet returns a new SortedSet containing the listed elements.
func UnionSortedSet ¶
func UnionSortedSet[E comparable](s1, s2 *SortedSet[E]) *SortedSet[E]
UnionSortedSet constructs a new set containing the union of s1 and s2.
func (*SortedSet[E]) Clear ¶
func (s *SortedSet[E]) Clear()
Clear removes all elements from s, leaving it empty.
func (*SortedSet[E]) Clone ¶
Clone returns a copy of s. The elements are copied using assignment, so this is a shallow clone.
func (*SortedSet[E]) ContainsAll ¶
ContainsAll reports whether all of the elements in s2 are in s.
func (*SortedSet[E]) ContainsAny ¶
ContainsAny reports whether any of the elements in s2 are in s.
func (*SortedSet[E]) Do ¶
Do calls f on every Eent in the set s, stopping if f returns false. f should not change s. f will be called on values in an indeterminate order.
func (*SortedSet[E]) Remove ¶
func (s *SortedSet[E]) Remove(v ...E)
Remove removes elements from a set. elements that are not present are ignored.