Documentation
¶
Overview ¶
Package set provides a Go implementation of the Set data structure, with a number of useful methods which can be performed on the Set.
Index ¶
- type Pair
- type Set
- func (s *Set) Add(value interface{}) bool
- func (s *Set) CartesianProduct(t *Set) *Set
- func (s *Set) Clone() *Set
- func (s *Set) Difference(t *Set) *Set
- func (s *Set) Enumerate() []interface{}
- func (s *Set) Equal(t *Set) bool
- func (s *Set) Filter(fn func(interface{}) bool) *Set
- func (s *Set) Has(value interface{}) bool
- func (s *Set) Intersection(t *Set) *Set
- func (s *Set) Map(fn func(interface{}) interface{}) *Set
- func (s *Set) PowerSet() *Set
- func (s *Set) Reduce(value interface{}, fn func(interface{}, interface{}) interface{}) interface{}
- func (s *Set) Remove(value interface{}) bool
- func (s *Set) Size() int
- func (s *Set) String() string
- func (s *Set) Subset(t *Set) bool
- func (s *Set) SymmetricDifference(t *Set) *Set
- func (s *Set) Union(t *Set) *Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pair ¶
type Pair struct { X interface{} Y interface{} }
Pair represents a pair of elements created from a cartesian product
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents an unordered collection of unique values
func New ¶
func New(values ...interface{}) *Set
New creates a new Set, and initializes its internal map, optionally adding initial elements to the set
func (*Set) Add ¶
Add inserts a new element into the set, returning true if the element was newly added, or false if it already existed
func (*Set) CartesianProduct ¶
CartesianProduct returns a set containing ordered pairs of every permutation between two sets
func (*Set) Difference ¶
Difference returns a set containing all elements present in this set, but without any elements present in the parameter set
func (*Set) Enumerate ¶
func (s *Set) Enumerate() []interface{}
Enumerate returns an unordered slice of all elements in the set
func (*Set) Equal ¶
Equal returns whether or not two sets have the same length and no differences, meaning they are equal
func (*Set) Filter ¶
Filter applies a function over all elements of the set, and returns all elements which return true when the function is applied
func (*Set) Intersection ¶
Intersection returns a set containing all elements present in both the current set and the parameter set
func (*Set) Map ¶
Map applies a function over all elements of the set, and returns the resulting set
func (*Set) Reduce ¶
func (s *Set) Reduce(value interface{}, fn func(interface{}, interface{}) interface{}) interface{}
Reduce applies a function over all elements of the set, accumulating the results into a final result value
func (*Set) Remove ¶
Remove destroys an element in the set, returning true if the element was destroyed, or false if it did not exist
func (*Set) Subset ¶
Subset determines if a parameter set is a subset of elements within this set, returning true if it is a subset, or false if it is not
func (*Set) SymmetricDifference ¶
SymmetricDifference returns a set containing all elements which are not shared between this set and the parameter set