set

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[A any] struct {
	Add        func(A) bool
	Delete     func(A) bool
	Contains   func(A) bool
	Len        func() int
	ToSlice    func() []A
	Union      func(*Set[A]) *Set[A]
	Intersect  func(*Set[A]) *Set[A]
	Difference func(*Set[A]) *Set[A]
	Iterator   func() iterable.Iterator[A]
}

func Empty added in v0.2.3

func Empty[A comparable]() *Set[A]

func FromSlice added in v0.2.1

func FromSlice[A comparable](elems []A) *Set[A]

func FromSliceBy added in v0.2.1

func FromSliceBy[A any, K comparable](projection func(A) K, elems []A) *Set[A]

func NewSet

func NewSet[A comparable](elems iterable.Iterable[A]) *Set[A]

func NewSetBy

func NewSetBy[A any, K comparable](projection func(A) K, initialElements iterable.Iterable[A]) *Set[A]

NewSetBy allows creation of a set from an element type which isn't comparable.

Why is 'comparable' required?  Because this set implementation uses a map.
Unfortunately, it's not possible to add implementations of user-defined types for comparable.
This uses a projection function to create a `comparable` key.
VERY VERY VERY IMPORTANT NOTES about the projection function:
- it should be a pure function (no side effects)
- it should make intuitive sense
- don't mix sets which use different projections -- the results will be unpredictable and won't make sense

Jump to

Keyboard shortcuts

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