treeset

package
v0.0.0-...-0e264d2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: BSD-2-Clause, ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

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

func (*Iterator[T]) Begin

func (iterator *Iterator[T]) Begin()

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

func (*Iterator[T]) End

func (iterator *Iterator[T]) End()

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

func (*Iterator[T]) First

func (iterator *Iterator[T]) 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[T]) Index

func (iterator *Iterator[T]) Index() int

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

func (*Iterator[T]) Last

func (iterator *Iterator[T]) 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[T]) Next

func (iterator *Iterator[T]) 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[T]) NextTo

func (iterator *Iterator[T]) NextTo(f func(index int, value T) 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[T]) Prev

func (iterator *Iterator[T]) 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[T]) PrevTo

func (iterator *Iterator[T]) PrevTo(f func(index int, value T) 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[T]) Value

func (iterator *Iterator[T]) Value() T

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

type Set

type Set[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

Set holds elements in a red-black tree

func New

func New[K constraints.Ordered](values ...K) *Set[K]

NewWith instantiates a new empty set with the custom comparator.

func NewWith

func NewWith[K constraints.Ordered](comparator utils.Comparator[K], values ...K) *Set[K]

NewWith instantiates a new empty set with the custom comparator.

func (*Set[K]) Add

func (set *Set[K]) Add(items ...K)

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

func (*Set[K]) All

func (set *Set[K]) All(f func(index int, value K) 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[K]) Any

func (set *Set[K]) Any(f func(index int, value K) 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[K]) Clear

func (set *Set[K]) Clear()

Clear clears all values in the set.

func (*Set[K]) Contains

func (set *Set[K]) Contains(items ...K) 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[T]) Difference

func (set *Set[T]) Difference(another *Set[T]) *Set[T]

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[K]) Each

func (set *Set[K]) Each(f func(index int, value K))

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

func (*Set[K]) Empty

func (set *Set[K]) Empty() bool

Empty returns true if set does not contain any elements.

func (*Set[K]) Find

func (set *Set[K]) Find(f func(index int, value K) bool) (int, K)

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[K]) FromJSON

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

FromJSON populates the set from the input JSON representation.

func (*Set[K]) Intersection

func (set *Set[K]) Intersection(another *Set[K]) *Set[K]

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[T]) Iterator

func (set *Set[T]) Iterator() Iterator[T]

Iterator holding the iterator's state

func (*Set[K]) Map

func (set *Set[K]) Map(f func(index int, value K) K) *Set[K]

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

func (*Set[K]) MarshalJSON

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

MarshalJSON @implements json.Marshaler

func (*Set[K]) Remove

func (set *Set[K]) Remove(items ...K)

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

func (*Set[K]) Select

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

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

func (*Set[K]) Size

func (set *Set[K]) Size() int

Size returns number of elements within the set.

func (*Set[K]) String

func (set *Set[K]) String() string

String returns a string representation of container

func (*Set[_]) ToJSON

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

ToJSON outputs the JSON representation of the set.

func (*Set[K]) Union

func (set *Set[K]) Union(another *Set[K]) *Set[K]

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[K]) UnmarshalJSON

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

UnmarshalJSON @implements json.Unmarshaler

func (*Set[K]) Values

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

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