example

package
v0.0.0-...-8f1dc17 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 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

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 StringComparator = func(a, b interface{}) int { return container.StringComparator(a.(string), b.(string)) }

Functions

func MultiStringSetIntersection

func MultiStringSetIntersection(a *MultiStringSet, b *MultiStringSet, callback func(elem string))

func StringSetIntersection

func StringSetIntersection(a *StringSet, b *StringSet, callback func(elem string))

Types

type IteratorMultiStringSet

type IteratorMultiStringSet struct {
	rbt.Iterator
}

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

func (IteratorMultiStringSet) Value

func (iterator IteratorMultiStringSet) Value() string

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

type IteratorStringSet

type IteratorStringSet struct {
	rbt.Iterator
}

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

func (IteratorStringSet) Value

func (iterator IteratorStringSet) Value() string

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

type MultiStringSet

type MultiStringSet struct {
	*rbt.Tree
}

Set holds elements in a red-black Tree

func CopyFromMultiStringSet

func CopyFromMultiStringSet(ts *MultiStringSet) *MultiStringSet

func NewMultiStringSet

func NewMultiStringSet(Value ...string) *MultiStringSet

func (*MultiStringSet) Add

func (set *MultiStringSet) Add(items ...string)

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

func (*MultiStringSet) AddItem

func (set *MultiStringSet) AddItem(item string) (bool, string)

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

func (*MultiStringSet) Begin

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

func (*MultiStringSet) Contains

func (set *MultiStringSet) Contains(items ...string) 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 (*MultiStringSet) Each

func (set *MultiStringSet) Each(f func(value string))

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

func (*MultiStringSet) End

End returns End Iterator

func (*MultiStringSet) Find

func (set *MultiStringSet) Find(f func(value string) bool) (v string)

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 (*MultiStringSet) Iterator

func (set *MultiStringSet) Iterator() IteratorMultiStringSet

Iterator holding the iterator's state

func (*MultiStringSet) LowerBound

func (set *MultiStringSet) LowerBound(item string) IteratorMultiStringSet

func (MultiStringSet) MarshalJSON

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

ToJSON outputs the JSON representation of the set.

func (MultiStringSet) Pack

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

func (*MultiStringSet) Remove

func (set *MultiStringSet) Remove(items ...string)

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

func (*MultiStringSet) String

func (set *MultiStringSet) String() string

String returns a string representation of container

func (*MultiStringSet) UnmarshalJSON

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

FromJSON populates the set from the input JSON representation.

func (*MultiStringSet) Unpack

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

func (*MultiStringSet) UpperBound

func (set *MultiStringSet) UpperBound(item string) IteratorMultiStringSet

func (*MultiStringSet) Values

func (set *MultiStringSet) Values() []string

Values returns all items in the set.

type StringSet

type StringSet struct {
	*rbt.Tree
}

Set holds elements in a red-black Tree

func CopyFromStringSet

func CopyFromStringSet(ts *StringSet) *StringSet

func NewStringSet

func NewStringSet(Value ...string) *StringSet

func (*StringSet) Add

func (set *StringSet) Add(items ...string)

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

func (*StringSet) AddItem

func (set *StringSet) AddItem(item string) (bool, string)

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

func (*StringSet) Begin

func (set *StringSet) Begin() IteratorStringSet

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

func (*StringSet) Contains

func (set *StringSet) Contains(items ...string) 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 (*StringSet) Each

func (set *StringSet) Each(f func(value string))

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

func (*StringSet) End

func (set *StringSet) End() IteratorStringSet

End returns End Iterator

func (*StringSet) Find

func (set *StringSet) Find(f func(value string) bool) (v string)

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 (*StringSet) Iterator

func (set *StringSet) Iterator() IteratorStringSet

Iterator holding the iterator's state

func (*StringSet) LowerBound

func (set *StringSet) LowerBound(item string) IteratorStringSet

func (StringSet) MarshalJSON

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

ToJSON outputs the JSON representation of the set.

func (StringSet) Pack

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

func (*StringSet) Remove

func (set *StringSet) Remove(items ...string)

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

func (*StringSet) String

func (set *StringSet) String() string

String returns a string representation of container

func (*StringSet) UnmarshalJSON

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

FromJSON populates the set from the input JSON representation.

func (*StringSet) Unpack

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

func (*StringSet) UpperBound

func (set *StringSet) UpperBound(item string) IteratorStringSet

func (*StringSet) Values

func (set *StringSet) Values() []string

Values returns all items in the set.

Jump to

Keyboard shortcuts

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