Documentation ¶
Index ¶
- func SortedList[T constraints.Ordered](s Set[T]) []T
- type Set
- func (s Set[T]) Contains(item T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Delete(item T) Set[T]
- func (s Set[T]) DeleteAll(items ...T) Set[T]
- func (s Set[T]) Difference(s2 Set[T]) Set[T]
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[T]) Insert(item T) Set[T]
- func (s Set[T]) InsertAll(items ...T) Set[T]
- func (s Set[T]) InsertContains(item T) bool
- func (s Set[T]) Intersection(s2 Set[T]) Set[T]
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) Len() int
- func (s Set[T]) Merge(s2 Set[T]) Set[T]
- func (s Set[T]) SupersetOf(s2 Set[T]) bool
- func (s Set[T]) Union(s2 Set[T]) Set[T]
- func (s Set[T]) UnsortedList() []T
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortedList ¶
func SortedList[T constraints.Ordered](s Set[T]) []T
SortedList returns the slice with contents sorted.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
func NewWithLength ¶
func NewWithLength[T comparable](l int) Set[T]
NewWithLength returns an empty Set with the given capacity. It's only a hint, not a limitation.
func (Set[T]) Difference ¶
Difference returns a set of objects that are not in s2 For example: s = {a1, a2, a3} s2 = {a1, a2, a4, a5} s.Difference(s2) = {a3} s2.Difference(s) = {a4, a5}
func (Set[T]) InsertContains ¶
InsertContains inserts the item into the set and returns if it was already present. Example:
if !set.InsertContains(item) { fmt.Println("Added item for the first time", item) }
func (Set[T]) Intersection ¶
Intersection returns a set of objects that are common between s and s2 For example: s = {a1, a2, a3} s2 = {a1, a2, a4, a5} s.Intersection(s2) = {a1, a2}
func (Set[T]) Merge ¶
Merge a set of objects that are in s2 into s For example: s = {a1, a2, a3} s2 = {a3, a4, a5} s.Merge(s2) = {a1, a2, a3, a4, a5}
func (Set[T]) SupersetOf ¶
SupersetOf returns true if s contains all elements of s2 For example: s = {a1, a2, a3} s2 = {a1, a2, a3, a4, a5} s.SupersetOf(s2) = false s2.SupersetOf(s) = true
func (Set[T]) Union ¶
Union returns a set of objects that are in s or s2 For example: s = {a1, a2, a3} s2 = {a1, a2, a4, a5} s.Union(s2) = s2.Union(s) = {a1, a2, a3, a4, a5}
func (Set[T]) UnsortedList ¶
func (s Set[T]) UnsortedList() []T
UnsortedList returns the slice with contents in random order.