Documentation ¶
Overview ¶
Package treeset implements an immutable Set datastructure on top of treemap
A note about Value comparability, by default, go's comparison operators will be used for any comparable type. Any type may implement the Compare(other interface{}) int interface to override this requirement.
Index ¶
- type Set
- func (s *Set) Add(elem interface{}) *Set
- func (s *Set) Apply(args ...interface{}) interface{}
- func (s *Set) At(elem interface{}) interface{}
- func (s *Set) Conj(elem interface{}) interface{}
- func (s *Set) Contains(elem interface{}) bool
- func (s *Set) Delete(elem interface{}) *Set
- func (s *Set) Equal(o interface{}) bool
- func (s *Set) Find(elem interface{}) (interface{}, bool)
- func (s *Set) Length() int
- func (s *Set) Range(do interface{})
- func (s *Set) Seq() seq.Sequence
- func (s *Set) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a persistent unordered set implementation.
func From ¶
From will convert many different go types to an immutable map. Converting some types is more efficient than others and the mechanisms are described below.
*Set:
Returned directly as it is already immutable.
map[interface{}]struct{}:
Converted directly by looping over the map and calling Add starting with an empty transient set. The transient set is the converted to a persistent one and returned.
[]interface{}:
The elements are passed to New.
map[kT]vT:
Reflection is used to loop over the keys of the map and add them to an empty transient set. The transient set is converted to a persistent map and then returned.
[]T:
Reflection is used to convert the slice to add the elements to the set.
seq.Sequence:
The sequence is reduced into a transient set that is made persistent on return.
seq.Sequable:
A sequence is obtained using Seq() and then the sequence is reduced into a transient set that is made persistent on return.
func (*Set) Apply ¶
func (s *Set) Apply(args ...interface{}) interface{}
Apply takes an arbitrary number of arguments and returns the value At the first argument. Apply allows set to be called as a function by the 'dyn' library.
func (*Set) At ¶
func (s *Set) At(elem interface{}) interface{}
At returns the elem if it exists in the set otherwise it returns nil.
func (*Set) Conj ¶
func (s *Set) Conj(elem interface{}) interface{}
Conj adds an element to the set. Conj implements a generic mechanism for building collections.
func (*Set) Delete ¶
Delete removes an element from the set returning a new Set without the element.
func (*Set) Equal ¶
Equal tests if two sets are Equal by comparing the entries of each. Equal implements the Equaler which allows for deep comparisons when there are sets of sets
func (*Set) Find ¶
Find will return the key if it exists in the set and whether the key exists in the set. If the key is not in the set, (nil, false) is returned.
func (*Set) Range ¶
func (s *Set) Range(do interface{})
Range calls the passed in function on each element of the set. The function passed in may be of many types:
func(value interface{}) bool:
Takes a value of any type and returns if the loop should continue. Useful to avoid reflection where not needed and to support heterogenous sets.
func(value interface{})
Takes a value of any type. Useful to avoid reflection where not needed and to support heterogenous sets.
func(value T) bool:
Takes a value of the type of element stored in the set and returns if the loop should continue. Useful for homogeneous sets. Is called with reflection and will panic if the type is incorrect.
func(value T)
Takes a value of the type of element stored in the set and returns if the loop should continue. Useful for homogeneous sets. Is called with reflection and will panic if the type is incorrect.
Range will panic if passed anything that doesn't match one of these signatures