set

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package set provides a set type with some useful helper functions.

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 unique, unordered collection of elements.

func New added in v0.7.5

func New[T comparable](sorter func([]T), items ...T) Set[T]

New creates a new set.

func NewBoolSet

func NewBoolSet(items ...bool) Set[bool]

NewBoolSet returns a set of bools

func NewIntSet

func NewIntSet(items ...int) Set[int]

NewIntSet returns a set of ints.

func NewStringSet

func NewStringSet(items ...string) Set[string]

NewStringSet returns a set of strings.

func NewTimestampSet

func NewTimestampSet(items ...time.Time) Set[time.Time]

NewTimestampSet returns a set of time.Times

func NewUUIDSet

func NewUUIDSet(items ...uuid.UUID) Set[uuid.UUID]

NewUUIDSet returns a set of uuid.UUIDs

func (Set[T]) Contains

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

Contains checks if the set contains the element.

func (Set[T]) Difference

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

Difference returns elements of the set not in the other.

func (Set[T]) Equal

func (s Set[T]) Equal(other Set[T]) bool

Equal checks whether two sets contain the same elements.

func (Set[T]) Evict

func (s Set[T]) Evict(item T) bool

Evict removes an item from the set and returns whether the item was present.

func (Set[T]) Insert

func (s Set[T]) Insert(items ...T)

Insert inserts the items into the set.

func (Set[T]) Intersection

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

Intersection returns elements common to both sets.

func (Set[T]) IsSupersetOf

func (s Set[T]) IsSupersetOf(other Set[T]) bool

IsSupersetOf checks if the set contains all the elements of the other set.

func (Set[T]) Items

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

Items returns a sorted slice of the set elements.

func (Set[T]) Size

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

Size returns the number of items in the set

func (Set[T]) String

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

String implements fmt.Stringer.

func (Set[T]) SymmetricDifference

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

SymmetricDifference returns elements of both sets that are not in the other.

This is a shortcut for calling x.Difference(y) + y.Difference(x).

func (Set[T]) Union

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

Union returns a set with elements in either of the sets.

Jump to

Keyboard shortcuts

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