Documentation
¶
Index ¶
- type HashFn
- type ISet
- type RingQueue
- type Set
- func (s Set[V]) All() iter.Seq2[int, V]
- func (s Set[V]) Clear()
- func (s Set[V]) Clone() Set[V]
- func (s Set[V]) Difference(others ...Set[V]) Set[V]
- func (s Set[V]) Each(fn func(v V))
- func (s Set[V]) EachWithErrs(fn func(key V) error) []error
- func (s Set[V]) Equal(to Set[V]) bool
- func (s Set[V]) Has(k V) bool
- func (s Set[V]) InPlaceDifference(others ...Set[V]) Set[V]
- func (s Set[V]) InPlaceIntersection(others ...Set[V]) Set[V]
- func (s Set[V]) InPlaceUnion(others ...Set[V]) Set[V]
- func (s Set[V]) Intersection(others ...Set[V]) Set[V]
- func (s Set[V]) IsDisjoint(other Set[V]) bool
- func (s Set[V]) IsProperSubset(to Set[V]) bool
- func (s Set[V]) IsProperSuperset(to Set[V]) bool
- func (s Set[V]) IsSubset(of Set[V]) bool
- func (s Set[V]) IsSuperset(of Set[V]) bool
- func (s Set[V]) Keys() []V
- func (s Set[V]) MarshalJSON() ([]byte, error)
- func (s Set[V]) Put(k V)
- func (s Set[V]) Remove(k V)
- func (s Set[V]) Size() int
- func (s Set[V]) String() string
- func (s Set[V]) SymmetricDifference(others ...Set[V]) Set[V]
- func (s Set[V]) Union(others ...Set[V]) Set[V]
- func (s Set[V]) Values() []V
- type Stack
- type Tuple
- type TupleWithErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ISet ¶
type ISet[V any] interface { Has(k V) bool Remove(k V) Put(k V) Clear() Copy() ISet[V] Size() int String() string Values() []V New() ISet[V] All() iter.Seq2[int, V] }
ISet is the internal representation of a set, you may implement your own if desired.
type RingQueue ¶
type RingQueue[T any] struct { // contains filtered or unexported fields }
func NewRingQueue ¶
NewRingQueue creates a new RingQueue with the given capacity and synchronization flag. If synchronized, operations require locks.
func (*RingQueue[T]) Items ¶
func (r *RingQueue[T]) Items() []T
Items returns all elements in the queue. The order is oldest to newest.
func (*RingQueue[T]) Iter ¶
Iter returns an iterator that yields all elements in the ring queue oldest to newest. Empty elements are not yielded
func (*RingQueue[T]) Iter2 ¶
Iter2 returns an iterator that yields all elements in the ring queue oldest to newest. Empty elements are not yielded
func (*RingQueue[T]) Pop ¶
func (r *RingQueue[T]) Pop() T
Pop removes the oldest element in the queue and returns it. If the queue is empty, it returns the zero value of the type.
type Set ¶
type Set[V any] struct { // contains filtered or unexported fields }
func NewCustomSet ¶
NewCustomSet creates a new set with the provided ISet implementation
func NewHashSet ¶
NewHashSet creates a new set with the provided values. Supports any type.
func NewHashSetWithHashFn ¶
func NewSet ¶
func NewSet[V comparable](values ...V) Set[V]
NewSet creates a new set with the provided values. Supports only comparable types.
func (Set[V]) All ¶
All returns an iterator that yields all elements in the set in the order they were inserted.
func (Set[V]) Difference ¶
Difference returns a new set with the difference of the current set and others
func (Set[V]) Each ¶
func (s Set[V]) Each(fn func(v V))
Each calls 'fn' on every item in the set in no particular order.
func (Set[V]) EachWithErrs ¶
EachWithErrs calls 'fn' on every item in the set in no particular order. All errors are aggregated and returned
func (Set[V]) InPlaceDifference ¶
InPlaceDifference will modify the current set in place to become the difference with others
func (Set[V]) InPlaceIntersection ¶
InPlaceIntersection will modify the current set in place to become the intersection with others
func (Set[V]) InPlaceUnion ¶
InPlaceUnion will modify the current set in place to become the union with others
func (Set[V]) Intersection ¶
Intersection returns a new set with the intersection of the current set and others
func (Set[V]) IsDisjoint ¶
IsDisjoint returns true if the current set has no elements in common with others
func (Set[V]) IsProperSubset ¶
IsProperSubset returns true if the current set is a proper subset of others
func (Set[V]) IsProperSuperset ¶
IsProperSuperset returns true if the current set is a proper superset of others
func (Set[V]) IsSuperset ¶
IsSuperset returns true if the current set is a superset of others
func (Set[V]) MarshalJSON ¶
func (Set[V]) SymmetricDifference ¶
SymmetricDifference returns a new set with the symmetric difference of the current set and others
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack implements a LIFO stack with peeking.
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (t T)
Peek returns the stack's top element but does not remove it. If the stack is empty the zero value is returned.
func (*Stack[T]) Pop ¶
func (s *Stack[T]) Pop() (t T)
Pop removes the stack's top element and returns it. If the stack is empty it returns the zero value.
type TupleWithErr ¶
func (TupleWithErr[A, B]) HasError ¶
func (t TupleWithErr[A, B]) HasError() bool
func (TupleWithErr[A, B]) HasValue ¶
func (t TupleWithErr[A, B]) HasValue() bool
HasValue returns true if the tuple has a non-zero value set for either A or B