sets

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT-0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreEqual

func AreEqual[SetA, SetB CountableSetOf[T], T any](setA SetA, setB SetB) bool

AreEqual returns true if the specified sets contain the same elements.

func CardinalityOf

func CardinalityOf[T any](s CountableSetOf[T]) int

CardinalityOf returns the cardinality of the set.

Calling it on an infinite set will result in an infinite loop.

func ContainsAnyOf

func ContainsAnyOf[T any](s SetOf[T], vs ...T) bool

ContainsAnyOf returns true if s contains any of the specified values

func QuickCardinalityOf

func QuickCardinalityOf[T any](s CountableSetOf[T]) (int, bool)

QuickCardinalityOf returns the cardinality of the set if it can be determined without counting its elements.

Types

type CountableSetOf

type CountableSetOf[T any] interface {
	SetOf[T]
	seqs.Seq[T]
}

CountableSetOf defines the interface of a countable set of T.

func CountableIntersectionOf

func CountableIntersectionOf[T any](setA, setB CountableSetOf[T]) CountableSetOf[T]

CountableIntersectionOf returns the intersection of the two specified countable sets.

func CountableRelativeComplementOf

func CountableRelativeComplementOf[T any](setA, setB CountableSetOf[T]) CountableSetOf[T]

CountableRelativeComplementOf returns the countable relative complement of set A in set B.

func CountableUnionOf

func CountableUnionOf[T any](setA, setB CountableSetOf[T]) CountableSetOf[T]

CountableUnionOf returns the union of the two specified countable sets.

type HashSet

type HashSet[T comparable] struct {
	MapKeySet[map[T]struct{}, T, struct{}]
}

func HashSetFromSeq

func HashSetFromSeq[T comparable](seq seqs.Seq[T]) (res HashSet[T])

func HashSetFromSlice added in v0.3.1

func HashSetFromSlice[T comparable](vs []T) (res HashSet[T])

func HashSetFromValues

func HashSetFromValues[T comparable](vs ...T) (res HashSet[T])

func (HashSet[T]) Clone added in v0.3.4

func (s HashSet[T]) Clone() HashSet[T]

func (*HashSet[T]) Exclude added in v0.2.0

func (s *HashSet[T]) Exclude(vs ...T)

func (*HashSet[T]) ExcludeSeq added in v0.2.0

func (s *HashSet[T]) ExcludeSeq(seq seqs.Seq[T])

func (*HashSet[T]) Include

func (s *HashSet[T]) Include(vs ...T)

func (*HashSet[T]) IncludeSeq

func (s *HashSet[T]) IncludeSeq(seq seqs.Seq[T])

type KeyedSet added in v0.3.2

type KeyedSet[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func KeyedSetFromSeq added in v0.3.2

func KeyedSetFromSeq[K comparable, V any](seq seqs.Seq[V], keyFn func(V) K) KeyedSet[K, V]

func KeyedSetFromSlice added in v0.3.2

func KeyedSetFromSlice[K comparable, V any](vs []V, keyFn func(V) K) KeyedSet[K, V]

func KeyedSetFromValues added in v0.3.2

func KeyedSetFromValues[K comparable, V any](keyFn func(V) K, vs ...V) (res KeyedSet[K, V])

func NewKeyedSet added in v0.3.2

func NewKeyedSet[K comparable, V any](keyFn func(V) K) KeyedSet[K, V]

func (KeyedSet[K, V]) Cardinality added in v0.3.2

func (s KeyedSet[K, V]) Cardinality() int

func (KeyedSet[K, V]) Clone added in v0.3.4

func (s KeyedSet[K, V]) Clone() KeyedSet[K, V]

func (KeyedSet[K, V]) Contains added in v0.3.2

func (s KeyedSet[K, V]) Contains(v V) bool

func (*KeyedSet[K, V]) Exclude added in v0.3.2

func (s *KeyedSet[K, V]) Exclude(vs ...V)

func (*KeyedSet[K, V]) ExcludeSeq added in v0.3.2

func (s *KeyedSet[K, V]) ExcludeSeq(seq seqs.Seq[V])

func (KeyedSet[K, V]) ForEachUntil added in v0.3.2

func (s KeyedSet[K, V]) ForEachUntil(fn func(V) bool)

func (KeyedSet[K, V]) GetByKey added in v0.3.3

func (s KeyedSet[K, V]) GetByKey(key K) (V, bool)

func (*KeyedSet[K, V]) Include added in v0.3.2

func (s *KeyedSet[K, V]) Include(vs ...V)

func (*KeyedSet[K, V]) IncludeSeq added in v0.3.2

func (s *KeyedSet[K, V]) IncludeSeq(seq seqs.Seq[V])

func (KeyedSet[K, V]) Len added in v0.4.0

func (s KeyedSet[K, V]) Len() int

type MapKeySet

type MapKeySet[M ~map[K]V, K comparable, V any] struct {
	Map M
}

func MapKeySetFrom

func MapKeySetFrom[M ~map[K]V, K comparable, V any](m M) MapKeySet[M, K, V]

func (MapKeySet[M, K, V]) Cardinality

func (s MapKeySet[M, K, V]) Cardinality() int

func (MapKeySet[M, K, V]) Clone added in v0.3.4

func (s MapKeySet[M, K, V]) Clone() MapKeySet[M, K, V]

func (MapKeySet[M, K, V]) Contains

func (s MapKeySet[M, K, V]) Contains(v K) bool

func (MapKeySet[M, K, V]) ForEachUntil added in v0.3.0

func (s MapKeySet[M, K, V]) ForEachUntil(fn func(K) bool)

func (MapKeySet[M, K, V]) Len added in v0.4.0

func (s MapKeySet[M, K, V]) Len() int

type Modifiable added in v0.2.0

type Modifiable[T any] interface {
	Exclude(...T)
	Include(...T)
}

Modifiable defines how a set can be modified.

type SetOf

type SetOf[T any] interface {
	Contains(T) bool
}

SetOf defines the minimal interface of a set of T.

func ComplementOf

func ComplementOf[T any](s SetOf[T]) SetOf[T]

ComplementOf returns the complement of the specified set.

func IntersectionOf

func IntersectionOf[T any](setA, setB SetOf[T]) SetOf[T]

IntersectionOf returns the intersection of the two specified sets.

func RelativeComplementOf

func RelativeComplementOf[T any](setA, setB SetOf[T]) SetOf[T]

RelativeComplementOf returns the relative complement of set A in set B.

This is also known as the set difference of B and A, denoted B \ A or B - A.

func UnionOf

func UnionOf[T any](setA, setB SetOf[T]) SetOf[T]

UnionOf returns the union of the two specified sets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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