set

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmptySet

func IsEmptySet[T comparable](s *Set[T]) bool

checks whether the set S is empty.

Types

type Set

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

https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Operations

func BuildSet

func BuildSet[T comparable](xn ...T) *Set[T]

creates a set structure with values x1,x2,...,xn.

func CreateFrom

func CreateFrom[T comparable](collection xcontainer.Iterator[T]) *Set[T]

creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator.

func CreateSet

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

creates a new, initially empty set structure.

func CreateSetWithCapacity

func CreateSetWithCapacity[T comparable](n int) *Set[T]

creates a new set structure, initially empty but capable of holding up to n elements.

func (*Set[T]) Add

func (s *Set[T]) Add(x T) error

adds the element x to S, if it is not present already.

func (*Set[T]) Capacity

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

returns the maximum number of values that S can hold.

func (*Set[T]) Clear

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

delete all elements of S.

func (*Set[T]) Enumerate

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

returns a list containing the elements of S in some arbitrary order.

func (*Set[T]) Equal

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

checks whether the two given sets are equal (i.e. contain all and only the same elements).

func (*Set[T]) Filter

func (s *Set[T]) Filter(p func(T) bool) *Set[T]

returns the subset containing all elements of S that satisfy a given predicate P.

func (*Set[T]) Hash

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

returns a hash value for the static set S such that if equal(S1, S2) then hash(S1) = hash(S2)

func (*Set[T]) IsElementOf

func (s *Set[T]) IsElementOf(x T) bool

checks whether the value x is in the set S.

func (*Set[T]) Iterate

func (s *Set[T]) Iterate() (xcontainer.IterateHandler[T], xcontainer.CancelHandler)

returns a function that returns one more value of S at each call, in some arbitrary order.

func (*Set[T]) Map

func (s *Set[T]) Map(f func(T) T) *Set[T]

returns the set of distinct values resulting from applying function F to each element of S.

func (*Set[T]) Pick

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

returns an arbitrary element of S. Functionally, the mutator pop can be interpreted as the pair of selectors (pick, rest), where rest returns the set consisting of all elements except for the arbitrary element. Can be interpreted in terms of iterate.

func (*Set[T]) Pop

func (s *Set[T]) Pop() (v T, ok bool)

returns an arbitrary element of S, deleting it from S

func (*Set[T]) Remove

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

removes the element x from S, if it is present.

func (*Set[T]) Size

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

returns the number of elements in S.

Jump to

Keyboard shortcuts

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