set

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBasicMap

func NewBasicMap[E comparable](sizeHint int) container.Set[E]

NewBasicMap returns a ready-for-use container.Set implemented by the BasicMap type.

Types

type BasicMap

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

BasicMap is the textbook Go implementation of a Go set using generics.

It is not concurrency-safe. For performance optimization, its union/intersection/difference operations may return the receiver or the argument instead of cloning.

func (*BasicMap[E]) Add

func (s *BasicMap[E]) Add(item E) (found bool)

Add adds an item to the set. Returns true if the item was already present.

func (*BasicMap[E]) Clear

func (s *BasicMap[E]) Clear() (count int)

Clear removes all items from the set and returns the number of items removed.

func (*BasicMap[E]) Contains

func (s *BasicMap[E]) Contains(item E) bool

Contains returns true if the item is present in the set.

func (*BasicMap[E]) Difference

func (s *BasicMap[E]) Difference(other container.Set[E]) container.Set[E]

Difference returns a new set containing elements present in this set but not in the other.

func (*BasicMap[E]) Intersection

func (s *BasicMap[E]) Intersection(other container.Set[E]) container.Set[E]

Intersection returns a new set containing elements present in both sets.

func (*BasicMap[E]) Items

func (s *BasicMap[E]) Items() iter.Seq[E]

Items returns an unordered iterator over the set'set elements.

func (*BasicMap[E]) Len

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

Len returns the number of items in the Set.

func (*BasicMap[E]) Remove

func (s *BasicMap[E]) Remove(item E) (found bool)

Remove removes an item from the set. It does not fail if the item was not present, and returns true if it was.

func (*BasicMap[E]) String

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

String returns an idiomatic unordered representation of the set items.

func (*BasicMap[E]) Union

func (s *BasicMap[E]) Union(other container.Set[E]) container.Set[E]

Union returns a new set containing elements present in either set.

Note that it may return one of its arguments without creating a clone.

Jump to

Keyboard shortcuts

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