set

package
v0.9.9 Latest Latest
Warning

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

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

Documentation

Overview

Package set provides a generic set data structure implementation.

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 a generic set data structure that stores unique values of any comparable type.

func NewSet

func NewSet[T comparable](vs ...T) Set[T]

NewSet creates and returns a new Set containing the provided values. Duplicate values in the input are automatically deduplicated.

func (Set[T]) Add

func (s Set[T]) Add(vs ...T)

Add adds one or more values to the set. If a value already exists in the set, it is not added again.

func (Set[T]) Has

func (s Set[T]) Has(v T) bool

Has returns true if the set contains the specified value.

func (Set[T]) Members

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

Members returns a slice containing all values in the set. The returned slice is independent of the set and can be modified without affecting the set. The order of elements is not guaranteed to be consistent across calls.

func (Set[T]) String

func (s Set[T]) String() string

String returns a string representation of the set in the format "[value1 value2 ...]".

Jump to

Keyboard shortcuts

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