set

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 3 modules, 50 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] interface {
	// Append adds multiple items to the set and returns the new size
	Append(val ...T) int

	// Remove removes an item from the set
	Remove(item T)

	// Contains checks if an item exists in the set
	Contains(item T) bool

	// Find returns the stored value for the given item if it exists
	// For case-insensitive sets, this returns the canonical (original) casing
	Find(item T) (T, bool)

	// Size returns the number of items in the set
	Size() int

	// Clear removes all items from the set
	Clear()

	// Clone returns a new set with a copy of all items
	Clone() Set[T]

	// Items returns all items in the set as a slice
	Items() []T

	// Iter returns an iterator over the set
	Iter() iter.Seq[T]

	// Union returns a new set containing all items from both sets
	Union(other Set[T]) Set[T]

	// Intersection returns a new set containing items present in both sets
	Intersection(other Set[T]) Set[T]

	// Difference returns a new set containing items present in this set but not in the other
	Difference(other Set[T]) Set[T]
}

Set defines the interface for set operations

func New

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

New creates a new empty non-thread-safe set with optional initial values

func NewCaseInsensitive added in v0.68.0

func NewCaseInsensitive(values ...string) Set[string]

NewCaseInsensitive creates a new empty case-insensitive string set with optional initial values The first occurrence of each unique string (case-insensitive) will be preserved. For example: NewCaseInsensitive("Hello", "HELLO", "world") will contain "Hello" and "world"

Jump to

Keyboard shortcuts

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