sets

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sets provides a set of functions for working with sets

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 set of elements T must be comparable, as map key, val uses empty struct to reduce space

func NewSet

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

NewSet creates a new set from a list of elements

func NewSetBySlice

func NewSetBySlice[T comparable, D any](slice []D, fn func(d D) T) Set[T]

func (Set[T]) Add

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

Add elements to set s if element is already in s this has no effect

func (Set[T]) Clone

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

Clone create a new set with the same elements as s

func (Set[T]) Complement

func (s Set[T]) Complement(t Set[T]) Set[T]

Complement returns the complement of two sets

func (Set[T]) Contains

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

Contains report wether v is in s

func (Set[T]) Difference

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

Difference returns the difference of two sets

func (Set[T]) Has

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

Contains report wether v is in s

func (Set[T]) Intersection

func (s Set[T]) Intersection(t Set[T]) Set[T]

Intersection returns the intersection of two sets

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty report weather s is empty

func (Set[T]) Len

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

Len report the elements number of s

func (Set[T]) MarshalJSON

func (s Set[T]) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Set[T]) Remove

func (s Set[T]) Remove(es ...T)

Remove elements from set s if element is not in s this has no effect

func (Set[T]) Slice

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

Slice transform set to slice

func (Set[T]) String

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

func (Set[T]) Union

func (s Set[T]) Union(t Set[T]) Set[T]

Union returns the union of two sets

func (*Set[T]) UnmarshalJSON

func (s *Set[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ...

Jump to

Keyboard shortcuts

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