set

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StopIteration = errors.New("stop iteration")
	RemoveItem    = errors.New("remove item")
)

Functions

This section is empty.

Types

type Boxed

type Boxed[T any] map[any]v

func FromArrayBoxed

func FromArrayBoxed[T any](membersArray []T) Boxed[T]

func FromBoxed

func FromBoxed[T any](members ...T) Boxed[T]

func NewBoxed

func NewBoxed[T any]() Boxed[T]

NewBoxed creates a new "boxed" Set, where the items stored in the set are boxed inside an interface. The values placed into the set must be comparable (i.e. suitable for use as a map key). This is checked at runtime and the code will panic on trying to add a non-comparable entry.

This implementation exists because Go's generics currently have a gap. The type set of the "comparable" constraint currently doesn't include interface types, which under Go's normal rules _are_ comparable (but may panic at runtime if the interface happens to contain a non-comparable object). If possible use a typed map via New() or From(); use this if you really need a Set[any] or Set[SomeInterface].

func (Boxed[T]) Add

func (set Boxed[T]) Add(item T)

func (Boxed[T]) AddAll

func (set Boxed[T]) AddAll(itemArray []T)

func (Boxed[T]) AddSet

func (set Boxed[T]) AddSet(other Set[T])

AddSet adds the contents of set "other" into the set.

func (Boxed[T]) Clear

func (set Boxed[T]) Clear()

func (Boxed[T]) Contains

func (set Boxed[T]) Contains(item T) bool

func (Boxed[T]) ContainsAll

func (set Boxed[T]) ContainsAll(other Set[T]) bool

func (Boxed[T]) Copy

func (set Boxed[T]) Copy() Set[T]

func (Boxed[T]) Discard

func (set Boxed[T]) Discard(item T)

func (Boxed[T]) Equals

func (set Boxed[T]) Equals(other Set[T]) bool

func (Boxed[T]) Iter

func (set Boxed[T]) Iter(visitor func(item T) error)

func (Boxed[T]) Len

func (set Boxed[T]) Len() int

func (Boxed[T]) Slice

func (set Boxed[T]) Slice() (s []T)

func (Boxed[T]) String

func (set Boxed[T]) String() string

type Set

type Set[T any] interface {
	Len() int
	Add(T)
	AddAll(itemArray []T)
	AddSet(other Set[T])
	Discard(T)
	Clear()
	Contains(T) bool
	Iter(func(item T) error)
	Copy() Set[T]
	Equals(Set[T]) bool
	ContainsAll(Set[T]) bool
	Slice() []T
	fmt.Stringer
}

func Empty

func Empty[T any]() Set[T]

type Typed

type Typed[T comparable] map[T]v

func From

func From[T comparable](members ...T) Typed[T]

func FromArray

func FromArray[T comparable](membersArray []T) Typed[T]

func New

func New[T comparable]() Typed[T]

func (Typed[T]) Add

func (set Typed[T]) Add(item T)

func (Typed[T]) AddAll

func (set Typed[T]) AddAll(itemArray []T)

func (Typed[T]) AddSet

func (set Typed[T]) AddSet(other Set[T])

AddSet adds the contents of set "other" into the set.

func (Typed[T]) Clear

func (set Typed[T]) Clear()

func (Typed[T]) Contains

func (set Typed[T]) Contains(item T) bool

func (Typed[T]) ContainsAll

func (set Typed[T]) ContainsAll(other Set[T]) bool

func (Typed[T]) Copy

func (set Typed[T]) Copy() Set[T]

func (Typed[T]) Discard

func (set Typed[T]) Discard(item T)

func (Typed[T]) Equals

func (set Typed[T]) Equals(other Set[T]) bool

func (Typed[T]) Iter

func (set Typed[T]) Iter(visitor func(item T) error)

func (Typed[T]) Len

func (set Typed[T]) Len() int

func (Typed[T]) Slice

func (set Typed[T]) Slice() (s []T)

func (Typed[T]) String

func (set Typed[T]) String() string

Jump to

Keyboard shortcuts

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