Documentation ¶
Index ¶
- func DeleteCleanupLast[K comparable, T comparable](m map[K]Set[T], k K, v T)
- func InsertOrNew[K comparable, T comparable](m map[K]Set[T], k K, v T)
- func SortedList[T cmp.Ordered](s Set[T]) []T
- type Set
- func (s Set[T]) Contains(item T) bool
- func (s Set[T]) ContainsAll(s2 Set[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]) Diff(other Set[T]) (left []T, right []T)
- func (s Set[T]) Difference(s2 Set[T]) Set[T]
- func (s Set[T]) DifferenceInPlace(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]) IntersectInPlace(s2 Set[T]) Set[T]
- 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]) String() string
- 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 DeleteCleanupLast ¶
func DeleteCleanupLast[K comparable, T comparable](m map[K]Set[T], k K, v T)
DeleteCleanupLast removes an element from a set in a map of sets, deleting the key from the map if there are no keys left. Works well with InsertOrNew. Example:
sets.DeleteCleanupLast(m, key, value)
func InsertOrNew ¶
func InsertOrNew[K comparable, T comparable](m map[K]Set[T], k K, v T)
InsertOrNew inserts t into the set if the set exists, or returns a new set with t if not. Works well with DeleteCleanupLast. Example:
InsertOrNew(m, key, value)
func SortedList ¶
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]) ContainsAll ¶
ContainsAll is alias of SupersetOf returns true if s contains all elements of s2
func (Set[T]) Diff ¶
Diff takes a pair of Sets, and returns the elements that occur only on the left and right set.
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]) DifferenceInPlace ¶
DifferenceInPlace similar to Difference, but has better performance. Note: This function modifies s in place.
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]) IntersectInPlace ¶
IntersectInPlace similar to Intersection, but has better performance. Note: This function modifies s in place.
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]) String ¶
String returns a string representation of the set. Be aware that the order of elements is random so the string representation may vary. Use it only for debugging and logging.
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.