sets

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

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