Documentation ¶
Overview ¶
Package set provides ordered and un-ordered generic sets, and handy operations between them.
Index ¶
- func Contains[T comparable](a, b Set[T]) (yes bool)
- func ContainsAny[T comparable](a, b Set[T]) (yes bool)
- func Equal[T comparable](a, b Set[T]) (yes bool)
- type Set
- type Unordered
- func (u Unordered[T]) Add(v T)
- func (u Unordered[T]) Clear()
- func (u Unordered[T]) Clone() (rv Set[T])
- func (u Unordered[T]) Del(v T)
- func (u Unordered[T]) Has(v T) (ok bool)
- func (u Unordered[T]) Iter(it func(T) bool)
- func (u Unordered[T]) Len() int
- func (u Unordered[T]) Pop() (v T, ok bool)
- func (u Unordered[T]) ToSlice() (rv []T)
- func (u Unordered[T]) TryAdd(v T) (ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](a, b Set[T]) (yes bool)
Contains returns true if `a` has all elements from `b`.
func ContainsAny ¶
func ContainsAny[T comparable](a, b Set[T]) (yes bool)
ContainsAny returns true if `a` has at least one element from `b`.
func Equal ¶
func Equal[T comparable](a, b Set[T]) (yes bool)
Equal returns true if `a` and `b` has same length and elements.
Types ¶
type Set ¶
type Set[T comparable] interface { // Add adds item to the set. Add(T) // Del removes item, no-op if not present. Del(T) // Has checks if item is already present. Has(T) bool // TryAdd takes attempt to add item, returns false if it already there. TryAdd(T) bool // 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. Iter(func(T) bool) // ToSlice returns set as slice of items. ToSlice() []T // Clear removes all items. Clear() }
Set is the primary interface provided by the set package.
func Diff ¶
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 ¶
func Intersect[T comparable](a, b Set[T]) (rv Set[T])
Intersect returns new set with keys from `a` that present in `b`.
func NewOrdered ¶
func NewOrdered[T comparable]() Set[T]
NewOrdered create empty ordered set for given type.
func NewUnordered ¶
func NewUnordered[T comparable]() Set[T]
NewUnordered create empty unordered Set for given type.
func Union ¶
func Union[T comparable](a, b Set[T]) (rv Set[T])
Union returns new set with elements from both sets.
type Unordered ¶
type Unordered[T comparable] map[T]stub
Unordered is a simple and effective un-ordered generic set.