set

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: GPL-3.0 Imports: 4 Imported by: 5

README

set

This set package provides a generic unordered set implementation (using a map[E]struct{} under the hood).

Documentation.

See also sortedset.

License: GPL-3


Documentation

Overview

(TOC) This package provides a generic unordered set implementation (using a map under the hood).

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
}

func New

func New[E comparable](elements ...E) Set[E]

New returns a new Set containing the given elements (if any). If no elements are given, the type must be specified since it can't be inferred.

func (*Set[E]) Add

func (me *Set[E]) Add(elements ...E)

Add adds the given element(s) to the Set.

func (*Set[E]) All

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

All returns an iterator, e.g., for element := range aset.All() ...

func (*Set[E]) AllX

func (me *Set[E]) AllX(start ...int) iter.Seq2[int, E]

AllX returns an iterator, e.g., for count, element := range aset.AllX(1) ...

func (*Set[E]) Clear

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

Clear deletes all the elements in the Set.

func (*Set[E]) Clone

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

Clone returns a copy of this Set.

func (*Set[E]) Contains

func (me *Set[E]) Contains(element E) bool

Contains returns true if element is in the Set; otherwise returns false.

func (*Set[E]) Delete

func (me *Set[E]) Delete(elements ...E)

Delete deletes the given element(s) from the Set.

func (*Set[E]) Difference

func (me *Set[E]) Difference(other Set[E]) Set[E]

Difference returns a new Set that contains the elements which are in this Set that are not in the other Set.

func (*Set[E]) Equal

func (me *Set[E]) Equal(other Set[E]) bool

Equal returns true if this Set has the same elements as the other Set; otherwise returns false.

func (*Set[E]) Intersection

func (me *Set[E]) Intersection(other Set[E]) Set[E]

Intersection returns a new Set that contains the elements this Set has in common with the other Set.

func (*Set[E]) IsDisjoint

func (me *Set[E]) IsDisjoint(other Set[E]) bool

IsDisjoint returns true if this Set has no elements in common with the other Set; otherwise returns false.

func (*Set[E]) IsEmpty added in v1.0.1

func (me *Set[E]) IsEmpty() bool

IsEmpty returns true if there are no elements in the Set; otherwise returns false.

func (*Set[E]) IsSubsetOf

func (me *Set[E]) IsSubsetOf(other Set[E]) bool

IsSubsetOf returns true if this Set is a subset of the other Set, i.e., if every member of this Set is in the other Set; otherwise returns false.

func (Set[E]) IsSupersetOf

func (me Set[E]) IsSupersetOf(other Set[E]) bool

IsSupersetOf returns true if this Set is a superset of the other Set, i.e., if every member of the other Set is in this Set; otherwise returns false.

func (*Set[E]) Len

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

Len returns the number of elements in the Set.

func (*Set[E]) String

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

String returns a human readable string representation of the Set.

func (*Set[E]) SymmetricDifference

func (me *Set[E]) SymmetricDifference(other Set[E]) Set[E]

SymmetricDifference returns a new Set that contains the elements which are in this Set or the other Set—but not in both Sets.

func (*Set[E]) ToSlice

func (me *Set[E]) ToSlice() []E

ToSlice returns this Set's elements as an unsorted slice. For iteration either use this, or if you only need one value at a time, use [All] or [AllX]. To sort, use slices.Sorted (if E is cmp.Orderable).

func (*Set[E]) Union

func (me *Set[E]) Union(other Set[E]) Set[E]

Union returns a new Set that contains the elements from this Set and from the other Set (with no duplicates of course). See also Set.Unite.

func (*Set[E]) Unite

func (me *Set[E]) Unite(other Set[E])

Unite adds all the elements from other that aren't already in this Set to this Set. See also Set.Union.

Jump to

Keyboard shortcuts

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