set

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package set provides a minimal generic set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is an unordered collection of unique values. It is not safe for concurrent use.

func New

func New[T comparable](items ...T) Set[T]

New returns a set containing the given items.

func (Set[T]) Add

func (s Set[T]) Add(item T)

Add inserts an item into the set.

func (Set[T]) Cardinality

func (s Set[T]) Cardinality() int

Cardinality returns the number of items in the set.

func (Set[T]) Contains

func (s Set[T]) Contains(item T) bool

Contains reports whether the set contains item.

func (Set[T]) Difference

func (s Set[T]) Difference(other Set[T]) Set[T]

Difference returns a new set of the items in s that are not in other.

func (Set[T]) Intersect

func (s Set[T]) Intersect(other Set[T]) Set[T]

Intersect returns a new set of the items present in both s and other.

func (Set[T]) Iter

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

Iter iterates over the set's items in unspecified order.

func (Set[T]) ToSlice

func (s Set[T]) ToSlice() []T

ToSlice returns the set's items in unspecified order.

Jump to

Keyboard shortcuts

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