set

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package set is a tiny generics based implementation for a set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T cmp.Ordered] map[T]struct{}

Set represents a generic set of unique values of the same type.

The values must be sortable.

func NewSet

func NewSet[T cmp.Ordered](capacity ...int) Set[T]

NewSet instantiates a new set.

If capacity is not empty, all values will be summed and used as the initial capacity of the set. The minimum initial capacity is forced to 8.

func (Set[T]) Add

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

Add adds one or more values to the set.

func (Set[T]) Clone

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

Clone create a deep copy of the set.

func (Set[T]) Difference

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

Difference returns the difference of this and other set as a new set.

func (Set[T]) Exists

func (s Set[T]) Exists(value T) bool

Exists return true if the value is present in the set.

func (Set[T]) Intersection

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

Intersection returns the intersection of this and other set as a new set.

func (Set[T]) Iterate

func (s Set[T]) Iterate(f func(T) bool)

Iterate calls the closure for all values in the set (in random order).

If the closure returns false, any remaining values will be skipped.

func (Set[T]) IterateSorted

func (s Set[T]) IterateSorted(f func(T) bool)

IterateSorted calls the closure for all sorted values in the set.

If the closure returns false, any remaining values will be skipped.

func (Set[T]) Remove

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

Remove removes one or more values from the set.

func (Set[T]) Union

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

Union returns the union of this and other set as a new set.

func (Set[T]) Values

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

Values returns a slice of the values.

func (Set[T]) ValuesSorted

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

ValuesSorted returns a sorted slice of the values.

Jump to

Keyboard shortcuts

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