treeset

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: BSD-2-Clause, ISC Imports: 8 Imported by: 283

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

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

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

func (*Iterator) Begin added in v1.2.0

func (iterator *Iterator) Begin()

Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.

func (*Iterator) End added in v1.2.0

func (iterator *Iterator) End()

End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.

func (*Iterator) First added in v1.2.0

func (iterator *Iterator) First() bool

First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Index

func (iterator *Iterator) Index() int

Index returns the current element's index. Does not modify the state of the iterator.

func (*Iterator) Last added in v1.2.0

func (iterator *Iterator) Last() bool

Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.

func (*Iterator) NextTo added in v1.13.0

func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool

NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Prev added in v1.1.0

func (iterator *Iterator) Prev() bool

Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) PrevTo added in v1.13.0

func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool

PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Value

func (iterator *Iterator) Value() interface{}

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

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set holds elements in a red-black tree

func NewWith

func NewWith(comparator utils.Comparator, values ...interface{}) *Set

NewWith instantiates a new empty set with the custom comparator.

func NewWithIntComparator

func NewWithIntComparator(values ...interface{}) *Set

NewWithIntComparator instantiates a new empty set with the IntComparator, i.e. keys are of type int.

func NewWithStringComparator

func NewWithStringComparator(values ...interface{}) *Set

NewWithStringComparator instantiates a new empty set with the StringComparator, i.e. keys are of type string.

func (*Set) Add

func (set *Set) Add(items ...interface{})

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

func (*Set) All

func (set *Set) All(f func(index int, value interface{}) bool) bool

All passes each element of the container to the given function and returns true if the function returns true for all elements.

func (*Set) Any

func (set *Set) Any(f func(index int, value interface{}) bool) bool

Any passes each element of the container to the given function and returns true if the function ever returns true for any element.

func (*Set) Clear

func (set *Set) Clear()

Clear clears all values in the set.

func (*Set) Contains

func (set *Set) Contains(items ...interface{}) 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) Difference added in v1.16.0

func (set *Set) Difference(another *Set) *Set

Difference returns the difference between two sets. The two sets should have the same comparators, otherwise the result is empty set. The new set consists of all elements that are in "set" but not in "another". Ref: https://proofwiki.org/wiki/Definition:Set_Difference

func (*Set) Each

func (set *Set) Each(f func(index int, value interface{}))

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

func (*Set) Empty

func (set *Set) Empty() bool

Empty returns true if set does not contain any elements.

func (*Set) Find

func (set *Set) Find(f func(index int, value interface{}) bool) (int, interface{})

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) FromJSON added in v1.9.0

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

FromJSON populates the set from the input JSON representation.

func (*Set) Intersection added in v1.16.0

func (set *Set) Intersection(another *Set) *Set

Intersection returns the intersection between two sets. The new set consists of all elements that are both in "set" and "another". The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)

func (*Set) Iterator

func (set *Set) Iterator() Iterator

Iterator holding the iterator's state

func (*Set) Map

func (set *Set) Map(f func(index int, value interface{}) interface{}) *Set

Map invokes the given function once for each element and returns a container containing the values returned by the given function.

func (*Set) MarshalJSON added in v1.15.0

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

MarshalJSON @implements json.Marshaler

func (*Set) Remove

func (set *Set) Remove(items ...interface{})

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

func (*Set) Select

func (set *Set) Select(f func(index int, value interface{}) bool) *Set

Select returns a new container containing all elements for which the given function returns a true value.

func (*Set) Size

func (set *Set) Size() int

Size returns number of elements within the set.

func (*Set) String

func (set *Set) String() string

String returns a string representation of container

func (*Set) ToJSON added in v1.9.0

func (set *Set) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the set.

func (*Set) Union added in v1.16.0

func (set *Set) Union(another *Set) *Set

Union returns the union of two sets. The new set consists of all elements that are in "set" or "another" (possibly both). The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Union_(set_theory)

func (*Set) UnmarshalJSON added in v1.15.0

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

UnmarshalJSON @implements json.Unmarshaler

func (*Set) Values

func (set *Set) Values() []interface{}

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