set

package
v1.4.87 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

README

set

Go Report Card Documentation license

A simple set datastructure in Go, with generics!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrencySafeSet added in v1.3.6

type ConcurrencySafeSet[T comparable] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrencySafeSet represents a set of unique elements.

func NewConcurrencySafe added in v1.3.6

func NewConcurrencySafe[T comparable](ss ...T) *ConcurrencySafeSet[T]

NewConcurrencySafe returns a new concurrency-safe set.

func (*ConcurrencySafeSet[T]) Add added in v1.3.6

func (s *ConcurrencySafeSet[T]) Add(ss ...T) Set[T]

Add adds a list of elements to a set.

func (*ConcurrencySafeSet[T]) Copy added in v1.3.6

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

Copy returns a copy of a set.

func (*ConcurrencySafeSet[T]) Equals added in v1.4.22

func (s *ConcurrencySafeSet[T]) Equals(comp Set[T]) bool

Equals returns true if a given set is equal (has the same elements).

func (*ConcurrencySafeSet[T]) Has added in v1.3.6

func (s *ConcurrencySafeSet[T]) Has(e T) bool

Has returns true if an element is in a set.

func (*ConcurrencySafeSet[T]) Iter added in v1.4.87

func (s *ConcurrencySafeSet[T]) Iter() iter.Seq[T]

Iter returns an iterator for a copy of the set. Note that elements are iterated through in no particular order.

func (*ConcurrencySafeSet[T]) Join added in v1.3.6

func (s *ConcurrencySafeSet[T]) Join(ss Set[T]) Set[T]

Join joins two sets.

func (*ConcurrencySafeSet[T]) Remove added in v1.3.6

func (s *ConcurrencySafeSet[T]) Remove(ss ...T) Set[T]

Remove removes a list of elements from a set.

func (*ConcurrencySafeSet[T]) Size added in v1.3.7

func (s *ConcurrencySafeSet[T]) Size() int

Size returns the number of elements in the set.

func (*ConcurrencySafeSet[T]) Slice added in v1.3.6

func (s *ConcurrencySafeSet[T]) Slice() []T

Slice returns the set as a slice.

type Set

type Set[T comparable] interface {
	Has(T) bool
	Add(...T) Set[T]
	Remove(...T) Set[T]
	Join(Set[T]) Set[T]
	Iter() iter.Seq[T]
	Copy() Set[T]
	Slice() []T
	Size() int
	Equals(Set[T]) bool
}

Set represents a set of unique elements.

type SimpleSet added in v1.3.6

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

SimpleSet represents a set of unique elements.

func New

func New[T comparable](ss ...T) SimpleSet[T]

New returns a new simple set.

func (SimpleSet[T]) Add added in v1.3.6

func (s SimpleSet[T]) Add(ss ...T) Set[T]

Add adds a list of elements to a set.

func (SimpleSet[T]) Copy added in v1.3.6

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

Copy returns a copy of a set.

func (SimpleSet[T]) Equals added in v1.4.22

func (s SimpleSet[T]) Equals(comp Set[T]) bool

Equals returns true if a given set is equal (has the same elements).

func (SimpleSet[T]) Has added in v1.3.6

func (s SimpleSet[T]) Has(e T) bool

Has returns true if an element is in a set.

func (SimpleSet[T]) Iter added in v1.4.87

func (s SimpleSet[T]) Iter() iter.Seq[T]

Iter returns an iterator for the set. Note that elements are iterated through in no particular order.

func (SimpleSet[T]) Join added in v1.3.6

func (s SimpleSet[T]) Join(ss Set[T]) Set[T]

Join joins two sets.

func (SimpleSet[T]) Remove added in v1.3.6

func (s SimpleSet[T]) Remove(ss ...T) Set[T]

Remove removes a list of elements from a set.

func (SimpleSet[T]) Size added in v1.3.7

func (s SimpleSet[T]) Size() int

Size returns the number of elements in the set.

func (SimpleSet[T]) Slice added in v1.3.6

func (s SimpleSet[T]) Slice() []T

Slice returns the set as a slice.

Jump to

Keyboard shortcuts

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