set

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package set defines a Set type that holds a set of elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

A 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. Unlike maps, the zero value of a Set is usable; there is no equivalent to make. As with maps, concurrent calls to functions and methods that read values are fine; concurrent calls to functions and methods that write values are racy.

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 Of

func Of[E comparable](v ...E) *Set[E]

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

func (s *Set[E]) Add(v ...E)

Add adds elements to a set.

func (*Set[E]) AddSet

func (s *Set[E]) AddSet(s2 *Set[E])

AddSet adds the elements of set s2 to s.

func (*Set[E]) All added in v0.0.2

func (s *Set[E]) All() iter.Seq[E]

All returns an iterator over the elements in the set. The iteration order is not specified and is not guaranteed to be the same from one call to the next.

func (*Set[E]) Clear

func (s *Set[E]) Clear()

Clear removes all elements from s, leaving it empty.

func (*Set[E]) Clone

func (s *Set[E]) Clone() *Set[E]

Clone returns a copy of s. The elements are copied using assignment, so this is a shallow clone.

func (*Set[E]) Contains

func (s *Set[E]) Contains(v E) bool

Contains reports whether v is in the set.

func (*Set[E]) ContainsAll

func (s *Set[E]) ContainsAll(s2 *Set[E]) bool

ContainsAll reports whether all of the elements in s2 are in s.

func (*Set[E]) ContainsAny

func (s *Set[E]) ContainsAny(s2 *Set[E]) bool

ContainsAny reports whether any of the elements in s2 are in s.

func (*Set[E]) Equal

func (s *Set[E]) Equal(s2 *Set[E]) bool

Equal reports whether s and s2 contain the same elements.

func (*Set[E]) GoString

func (s *Set[E]) GoString() string

GoString returns a Go syntax representation of the set.

func (*Set[E]) Len

func (s *Set[E]) Len() int

Len returns the number of elements in s.

func (*Set[E]) Remove

func (s *Set[E]) Remove(v ...E)

Remove removes elements from a set. Elements that are not present are ignored.

func (*Set[E]) RemoveIf

func (s *Set[E]) RemoveIf(remove func(E) bool)

RemoveIf deletes any elements from s for which remove returns true.

func (*Set[E]) RemoveSet

func (s *Set[E]) RemoveSet(s2 *Set[E])

RemoveSet removes the elements of set s2 from s. Elements present in s2 but not s are ignored.

func (*Set[E]) String

func (s *Set[E]) String() string

String returns a human-readable representation of the set.

Jump to

Keyboard shortcuts

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