treeset

package
v0.0.0-...-c626c17 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package treeset implements a Tree backed by a red-black Tree.

Structure is not thread safe.

Reference: http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29

Index

Constants

This section is empty.

Variables

View Source
var Compare = func(a, b interface{}) int { return container.IntComparator(a.(int), b.(int)) }
View Source
var Multi = false

Functions

func SetIntersection

func SetIntersection(a *Set, b *Set, callback func(elem V))

Types

type Iterator

type Iterator struct {
	rbt.Iterator
}

Iterator returns a stateful iterator whose values can be fetched by an index.

func (Iterator) Value

func (iterator Iterator) Value() V

Value returns the current element's value. Does not modify the state of the iterator.

type Set

type Set struct {
	*rbt.Tree
}

Set holds elements in a red-black Tree

func CopyFrom

func CopyFrom(ts *Set) *Set

func New

func New(Value ...V) *Set

func (*Set) Add

func (set *Set) Add(items ...V)

Add adds the items (one or more) to the set.

func (*Set) AddItem

func (set *Set) AddItem(item V) (bool, V)

Add adds the item one to the set.Returns false and the interface if it already exists

func (*Set) Begin

func (set *Set) Begin() Iterator

Begin returns First Iterator whose position points to the first element Return End Iterator when the map is empty

func (*Set) Contains

func (set *Set) Contains(items ...V) bool

Contains checks weather items (one or more) are present in the set. All items have to be present in the set for the method to return true. Returns true if no arguments are passed at all, i.e. set is always superset of empty set.

func (*Set) Each

func (set *Set) Each(f func(value V))

Each calls the given function once for each element, passing that element's index and value.

func (*Set) End

func (set *Set) End() Iterator

End returns End Iterator

func (*Set) Find

func (set *Set) Find(f func(value V) bool) (v V)

Find passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.

func (*Set) Iterator

func (set *Set) Iterator() Iterator

Iterator holding the iterator's state

func (*Set) LowerBound

func (set *Set) LowerBound(item V) Iterator

func (Set) MarshalJSON

func (set Set) MarshalJSON() ([]byte, error)

ToJSON outputs the JSON representation of the set.

func (Set) Pack

func (set Set) Pack() (re []byte, err error)

func (*Set) Remove

func (set *Set) Remove(items ...V)

Remove removes the items (one or more) from the set.

func (*Set) String

func (set *Set) String() string

String returns a string representation of container

func (*Set) UnmarshalJSON

func (set *Set) UnmarshalJSON(data []byte) error

FromJSON populates the set from the input JSON representation.

func (*Set) Unpack

func (set *Set) Unpack(in []byte) (int, error)

func (*Set) UpperBound

func (set *Set) UpperBound(item V) Iterator

func (*Set) Values

func (set *Set) Values() []V

Values returns all items in the set.

type V

type V = int

template type Set(V,Compare,Multi)

Directories

Path Synopsis
Package treeset implements a Tree backed by a red-black Tree.
Package treeset implements a Tree backed by a red-black Tree.

Jump to

Keyboard shortcuts

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