treeset

package
v0.0.0-...-7241100 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 7 Imported by: 0

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

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 Empty

func Empty(options ...treemap.Option) *Set

Empty returns the empty set.

func From

func From(value interface{}, options ...treemap.Option) *Set

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 New

func New(elems ...interface{}) *Set

New returns a set containing the supplied elements.

func (*Set) Add

func (s *Set) Add(elem interface{}) *Set

Add adds an element to the set and a new set is returned.

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) Contains

func (s *Set) Contains(elem interface{}) bool

Contains returns true if the element is in the set, false otherwise.

func (*Set) Delete

func (s *Set) Delete(elem interface{}) *Set

Delete removes an element from the set returning a new Set without the element.

func (*Set) Equal

func (s *Set) Equal(o interface{}) bool

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

func (s *Set) Find(elem interface{}) (interface{}, bool)

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) Length

func (s *Set) Length() int

Length returns the elements in the set.

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

func (*Set) Seq

func (s *Set) Seq() seq.Sequence

Seq returns a seralized sequence of interface{} corresponding to the set's elements.

func (*Set) String

func (s *Set) String() string

String returns a string serialization of the set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL