sets

package
v0.0.0-...-6be268e Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 35

Documentation

Index

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

func SortedList[T cmp.Ordered](s Set[T]) []T

SortedList returns the slice with contents sorted.

Types

type Set

type Set[T comparable] map[T]struct{}

func New

func New[T comparable](items ...T) Set[T]

New creates a new Set with the given items.

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]) Contains

func (s Set[T]) Contains(item T) bool

Contains returns whether the given item is in the set.

func (Set[T]) ContainsAll

func (s Set[T]) ContainsAll(s2 Set[T]) bool

ContainsAll is alias of SupersetOf returns true if s contains all elements of s2

func (Set[T]) Copy

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

Copy this set.

func (Set[T]) Delete

func (s Set[T]) Delete(item T) Set[T]

Delete removes an item from the set.

func (Set[T]) DeleteAll

func (s Set[T]) DeleteAll(items ...T) Set[T]

DeleteAll removes items from the set.

func (Set[T]) Diff

func (s Set[T]) Diff(other Set[T]) (left []T, right []T)

Diff takes a pair of Sets, and returns the elements that occur only on the left and right set.

func (Set[T]) Difference

func (s Set[T]) Difference(s2 Set[T]) Set[T]

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

func (s Set[T]) DifferenceInPlace(s2 Set[T]) Set[T]

DifferenceInPlace similar to Difference, but has better performance. Note: This function modifies s in place.

func (Set[T]) Equals

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

Equals checks whether the given set is equal to the current set.

func (Set[T]) Insert

func (s Set[T]) Insert(item T) Set[T]

Insert a single item to this Set.

func (Set[T]) InsertAll

func (s Set[T]) InsertAll(items ...T) Set[T]

InsertAll adds the items to this Set.

func (Set[T]) InsertContains

func (s Set[T]) InsertContains(item T) bool

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

func (s Set[T]) IntersectInPlace(s2 Set[T]) Set[T]

IntersectInPlace similar to Intersection, but has better performance. Note: This function modifies s in place.

func (Set[T]) Intersection

func (s Set[T]) Intersection(s2 Set[T]) Set[T]

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]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty indicates whether the set is the empty set.

func (Set[T]) Len

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

Len returns the number of elements in this Set.

func (Set[T]) Merge

func (s Set[T]) Merge(s2 Set[T]) Set[T]

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

func (s Set[T]) String() 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

func (s Set[T]) SupersetOf(s2 Set[T]) bool

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

func (s Set[T]) Union(s2 Set[T]) Set[T]

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.

type String

type String = Set[string]

Jump to

Keyboard shortcuts

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