set

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package set implements a generic set container type.

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 container for a set of values.

func New

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

New returns a new Set.

func NewFromSlice

func NewFromSlice[T comparable](slice []T) *Set[T]

NewFromSlice returns a new set from a slice.

func (*Set[T]) Add

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

Add adds an element to the set

func (*Set[T]) All

func (s *Set[T]) All() iter.Seq[T]

All returns on iterator over all elements of a set. Note that sets are unordered, so elements will be returned in no particular order.

func (*Set[T]) Clear

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

Clear removes all elements from a set.

func (*Set[T]) Contains

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

Contains reports wether an item is in this set.

func (*Set[T]) Difference

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

Difference returns a new set which elements from current set, that does not exist in other set.

func (*Set[T]) Equal

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

Equal reports wether two sets are equal.

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

Intersect returns a new set which contains elements found in both sets only.

func (*Set[T]) Remove

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

Remove removes an element from a set. It does nothing when the element doesn't exist.

func (*Set[T]) Size

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

Size returns the number of elements in a set.

func (*Set[T]) String

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

func (*Set[T]) ToSlice

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

ToSlice converts a set to a slice and returns it. Note that the elements in the slice have no defined order.

func (*Set[T]) Union

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

Union returns a new set containing the combined elements from both sets.

Jump to

Keyboard shortcuts

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