collections

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package collections provides small, self-documenting generic container types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a collection of unique comparable elements. It replaces the ad-hoc map[T]bool idiom: membership is explicit, and a removed element is indistinguishable from one that was never present.

func NewSet

func NewSet[T comparable]() *Set[T]

NewSet creates an empty Set ready for use.

func (*Set[T]) Add

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

Add inserts item into the set. Adding an element already present is a no-op.

func (*Set[T]) Clear

func (s *Set[T]) Clear()

Clear removes every element, leaving an empty set.

func (*Set[T]) Contains

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

Contains reports whether item is currently a member of the set.

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len returns the number of elements currently in the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T)

Remove deletes item from the set. Removing an absent element is a no-op.

func (*Set[T]) Toggle

func (s *Set[T]) Toggle(item T)

Toggle flips the membership of item: it is removed when present and added when absent, with a single map lookup.

Jump to

Keyboard shortcuts

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