Documentation ¶
Overview ¶
Package set provides ordered and un-ordered generic sets, and handy operations between them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v1.1.0
func Contains[T comparable](a, b Set[T]) (yes bool)
Contains returns true if smallest of two sets (by length) fully contains inside bigger one, if sets equals in length the result is same as comparison.
func ContainsAny ¶ added in v1.1.0
func ContainsAny[T comparable](a, b Set[T]) (yes bool)
ContainsAny returns true if `a` has at least one element from `b`.
func Equal ¶ added in v1.1.0
func Equal[T comparable](a, b Set[T]) (yes bool)
Equal returns true if `a` and `b` has same length and elements.
func ToSlice ¶ added in v1.2.0
func ToSlice[T comparable](s Set[T]) (rv []T)
ToSlice returns set as slice of items.
Types ¶
type Set ¶
type Set[T comparable] interface { // Add adds item to the set. Add(T) bool // Has checks if item is already present. Has(T) bool // Del removes item, no-op if not present. Del(T) // Pop removes and returns an arbitrary item. Pop() (v T, ok bool) // Len returns current items count. Len() int // Clone returns shallow copy. Clone() Set[T] // Iter iterates items until callback returns false. Iter(func(T) bool) // Clear removes all items. Clear() }
Set is the primary interface provided by the set package.
func Diff ¶ added in v1.1.0
func Diff[T comparable](a, b Set[T]) (rv Set[T])
Diff returns new set with elements from `a` that arent in `b`.
func Intersect ¶ added in v1.1.0
func Intersect[T comparable](a, b Set[T]) (rv Set[T])
Intersect returns new set with keys from `a` that present in `b`.
func Load ¶ added in v1.1.0
func Load[T comparable](s Set[T], v ...T) Set[T]
Load populates given set with values.
func NewOrdered ¶ added in v1.1.0
func NewOrdered[T comparable]() Set[T]
NewOrdered create empty ordered set for given type.
func NewUnordered ¶ added in v1.1.0
func NewUnordered[T comparable]() Set[T]
NewUnordered create empty unordered Set for given type.
func Union ¶ added in v1.1.0
func Union[T comparable](a, b Set[T]) (rv Set[T])
Union returns new set with elements from both sets.
type Unordered ¶ added in v1.1.0
type Unordered[T comparable] map[T]stub
Unordered is a simple and effective un-ordered generic set.
func (Unordered[T]) Clear ¶ added in v1.1.0
func (u Unordered[T]) Clear()
Clear implements Set interface.
func (Unordered[T]) Del ¶ added in v1.1.0
func (u Unordered[T]) Del(v T)
Del implements Set interface.