package set
import "gomo.prashantv.com/container/set"
Package set implements set operations using a map.
Index
- func Ordered(s Set[T]) []T
-
type Set
- func New(items ...T) Set[T]
- func (s Set[T]) Contains(item T) bool
- func (s Set[T]) ContainsAll(items []T) bool
- func (s Set[T]) ContainsAny(items []T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Delete(item T)
- func (s Set[T]) DeleteExists(item T) bool
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[T]) Insert(item T)
- func (s Set[T]) InsertSeq(seq iter.Seq[T])
- func (s Set[T]) InsertUnique(item T) bool
- func (s Set[T]) Intersect(other Set[T]) Set[T]
- func (s Set[T]) Iter() iter.Seq[T]
- func (s Set[T]) SubsetOf(other Set[T]) bool
- func (s Set[T]) SupersetOf(other Set[T]) bool
- func (s Set[T]) Union(other Set[T]) Set[T]
- func (s Set[K]) Unordered() []K
Functions
func Ordered
func Ordered[T cmp.Ordered](s Set[T]) []T
Ordered returns an ordered set of values in the set.
Types
type Set
type Set[T comparable] map[T]struct{}
Set implements set operations using a `map[T]struct{}`. It is not safe for concurrent use.
func New
func New[T comparable](items ...T) Set[T]
New creates a set with items.
func (Set[T]) Contains
func (s Set[T]) Contains(item T) bool
Contains returns if the set contains the specified item.
func (Set[T]) ContainsAll
func (s Set[T]) ContainsAll(items []T) bool
ContainsAll returns if all the items exist in the set.
func (Set[T]) ContainsAny
func (s Set[T]) ContainsAny(items []T) bool
ContainsAny returns true if any of the items exist in the set. If no items are specified, it returns false.
func (Set[T]) Copy
func (s Set[T]) Copy() Set[T]
Copy returns a new set with the same items.
func (Set[T]) Delete
func (s Set[T]) Delete(item T)
Delete deletes the item from the set.
func (Set[T]) DeleteExists
func (s Set[T]) DeleteExists(item T) bool
DeleteExists deletes the item from the set if it exists. It returns true if the item was deleted.
func (Set[T]) Equals
func (s Set[T]) Equals(other Set[T]) bool
Equals returns if the two sets are equal.
func (Set[T]) Insert
func (s Set[T]) Insert(item T)
Insert inserts the item into the set, overwriting any existing items.
func (Set[T]) InsertSeq
func (s Set[T]) InsertSeq(seq iter.Seq[T])
InsertSeq inserts all values from seq into the set, overwriting any existing items.
func (Set[T]) InsertUnique
func (s Set[T]) InsertUnique(item T) bool
InsertUnique inserts the item into the set if the item is not already in the set. It returns true if the item did not previously exist, and was inserted.
func (Set[T]) Intersect
func (s Set[T]) Intersect(other Set[T]) Set[T]
Intersect returns a set that only contains items that are in both sets.
func (Set[T]) Iter
func (s Set[T]) Iter() iter.Seq[T]
Iter returns an iterator over all items in the set.
func (Set[T]) SubsetOf
func (s Set[T]) SubsetOf(other Set[T]) bool
SubsetOf returns if other contains all elements in s.
func (Set[T]) SupersetOf
func (s Set[T]) SupersetOf(other Set[T]) bool
SupersetOf returns if s contains all elements in other.
func (Set[T]) Union
func (s Set[T]) Union(other Set[T]) Set[T]
Union returns a set with elements from both sets.
func (Set[K]) Unordered
func (s Set[K]) Unordered() []K
Unordered returns an unordered set of values in the set. Since it relies on Go map iteration order, the order of the values is non-deterministic.
Use `Ordered` when deterministic output is required.