Documentation ¶
Index ¶
- type Iterator
- func (iterator *Iterator[K, V]) Begin()
- func (iterator *Iterator[K, V]) End()
- func (iterator *Iterator[K, V]) First() bool
- func (iterator *Iterator[K, V]) Key() K
- func (iterator *Iterator[K, V]) Last() bool
- func (iterator *Iterator[K, V]) Next() bool
- func (iterator *Iterator[K, V]) NextTo(f func(key K, value V) bool) bool
- func (iterator *Iterator[K, V]) Node() *Node[K, V]
- func (iterator *Iterator[K, V]) Prev() bool
- func (iterator *Iterator[K, V]) PrevTo(f func(key K, value V) bool) bool
- func (iterator *Iterator[K, V]) Value() V
- type Node
- type Tree
- func (tree *Tree[K, V]) Ceiling(key K) (ceiling *Node[K, V], found bool)
- func (tree *Tree[K, V]) Clear()
- func (tree *Tree[K, V]) Empty() bool
- func (tree *Tree[K, V]) Floor(key K) (floor *Node[K, V], found bool)
- func (tree *Tree[K, V]) FromJSON(data []byte) error
- func (tree *Tree[K, V]) Get(key K) (value V, found bool)
- func (tree *Tree[K, V]) GetNode(key K) *Node[K, V]
- func (tree *Tree[K, V]) Iterator() Iterator[K, V]
- func (tree *Tree[K, V]) IteratorAt(node *Node[K, V]) Iterator[K, V]
- func (tree *Tree[K, V]) Keys() []K
- func (tree *Tree[K, V]) Left() *Node[K, V]
- func (tree *Tree[K, V]) MarshalJSON() ([]byte, error)
- func (tree *Tree[K, V]) Put(key K, value V)
- func (tree *Tree[K, V]) Remove(key K)
- func (tree *Tree[K, V]) Right() *Node[K, V]
- func (tree *Tree[K, V]) Size() int
- func (tree *Tree[K, V]) String() string
- func (tree *Tree[K, V]) ToJSON() ([]byte, error)
- func (tree *Tree[K, V]) UnmarshalJSON(bytes []byte) error
- func (tree *Tree[K, V]) Values() []V
- type TreeMap
- func (m *TreeMap[K, V]) All(f func(key K, value V) bool) bool
- func (m *TreeMap[K, V]) Any(f func(key K, value V) bool) bool
- func (m *TreeMap[K, V]) Clear()
- func (m *TreeMap[K, V]) Each(f func(key K, value V))
- func (m *TreeMap[K, V]) Empty() bool
- func (m *TreeMap[K, V]) Find(f func(key K, value V) bool) TreeMapIterator[K, V]
- func (m *TreeMap[K, V]) FromJSON(data []byte) error
- func (m *TreeMap[K, V]) Get(key K) (value V, found bool)
- func (m *TreeMap[K, V]) Iterator() TreeMapIterator[K, V]
- func (m *TreeMap[K, V]) Keys() []K
- func (m *TreeMap[K, V]) LowerBound(key K) TreeMapIterator[K, V]
- func (m *TreeMap[K, V]) Map(f func(key1 K, value1 V) (K, V)) *TreeMap[K, V]
- func (m *TreeMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *TreeMap[K, V]) Max() (key K, value V, ok bool)
- func (m *TreeMap[K, V]) Min() (key K, value V, ok bool)
- func (m *TreeMap[K, V]) Put(key K, value V)
- func (m *TreeMap[K, V]) Remove(key K)
- func (m *TreeMap[K, V]) Select(f func(key K, value V) bool) *TreeMap[K, V]
- func (m *TreeMap[K, V]) Size() int
- func (m *TreeMap[K, V]) String() string
- func (m *TreeMap[K, V]) ToJSON() ([]byte, error)
- func (m *TreeMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (m *TreeMap[K, V]) UpperBound(key K) TreeMapIterator[K, V]
- func (m *TreeMap[K, V]) Values() []V
- type TreeMapIterator
- func (iterator *TreeMapIterator[K, V]) Begin()
- func (iterator *TreeMapIterator[K, V]) End()
- func (iterator *TreeMapIterator[K, V]) First() bool
- func (iterator *TreeMapIterator[K, V]) IsBegin() bool
- func (iterator *TreeMapIterator[K, V]) IsEnd() bool
- func (iterator *TreeMapIterator[K, V]) Key() K
- func (iterator *TreeMapIterator[K, V]) Last() bool
- func (iterator *TreeMapIterator[K, V]) Next() bool
- func (iterator *TreeMapIterator[K, V]) NextTo(f func(key K, value V) bool) bool
- func (iterator *TreeMapIterator[K, V]) Prev() bool
- func (iterator *TreeMapIterator[K, V]) PrevTo(f func(key K, value V) bool) bool
- func (iterator *TreeMapIterator[K, V]) Value() V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
Iterator holding the iterator's state
func (*Iterator[K, V]) Begin ¶
func (iterator *Iterator[K, V]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator[K, V]) End ¶
func (iterator *Iterator[K, V]) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator[K, V]) First ¶
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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator
func (*Iterator[K, V]) Key ¶
func (iterator *Iterator[K, V]) Key() K
Key returns the current element's key. Does not modify the state of the iterator.
func (*Iterator[K, V]) Last ¶
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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*Iterator[K, V]) Next ¶
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 key and value can be retrieved by Key() 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[K, V]) NextTo ¶
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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*Iterator[K, V]) Node ¶
Node returns the current element's node. Does not modify the state of the iterator.
func (*Iterator[K, V]) Prev ¶
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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*Iterator[K, V]) PrevTo ¶
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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
type Node ¶
type Node[K constraints.Ordered, V any] struct { Key K Value V Left *Node[K, V] Right *Node[K, V] Parent *Node[K, V] // contains filtered or unexported fields }
Node is a single element within the tree
type Tree ¶
type Tree[K constraints.Ordered, V any] struct { Root *Node[K, V] // contains filtered or unexported fields }
Tree holds elements of the red-black tree
func (*Tree[K, V]) Ceiling ¶
Ceiling finds ceiling node of the input key, return the ceiling node or nil if no ceiling is found. Second return parameter is true if ceiling was found, otherwise false.
Ceiling node is defined as the smallest node that is larger than or equal to the given node. A ceiling node may not be found, either because the tree is empty, or because all nodes in the tree are smaller than the given node.
Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) Floor ¶
Floor Finds floor node of the input key, return the floor node or nil if no floor is found. Second return parameter is true if floor was found, otherwise false.
Floor node is defined as the largest node that is smaller than or equal to the given node. A floor node may not be found, either because the tree is empty, or because all nodes in the tree are larger than the given node.
Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) Get ¶
Get searches the node in the tree by key and returns its value or nil if key is not found in tree. Second return parameter is true if key was found, otherwise false. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) GetNode ¶
GetNode searches the node in the tree by key and returns its node or nil if key is not found in tree. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) Iterator ¶
Iterator returns a stateful iterator whose elements are key/value pairs.
func (*Tree[K, V]) IteratorAt ¶
IteratorAt returns a stateful iterator whose elements are key/value pairs that is initialised at a particular node.
func (*Tree[K, V]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Tree[K, V]) Put ¶
func (tree *Tree[K, V]) Put(key K, value V)
Put inserts node into the tree. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) Remove ¶
func (tree *Tree[K, V]) Remove(key K)
Remove remove the node from the tree by key. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*Tree[K, V]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler
type TreeMap ¶
type TreeMap[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
func (*TreeMap[K, V]) All ¶
All passes each element of the container to the given function and returns true if the function returns true for all elements.
func (*TreeMap[K, V]) Any ¶
Any passes each element of the container to the given function and returns true if the function ever returns true for any element.
func (*TreeMap[K, V]) Clear ¶
func (m *TreeMap[K, V]) Clear()
Clear removes all elements from the map.
func (*TreeMap[K, V]) Each ¶
func (m *TreeMap[K, V]) Each(f func(key K, value V))
Each calls the given function once for each element, passing that element's key and value.
func (*TreeMap[K, V]) Find ¶
func (m *TreeMap[K, V]) Find(f func(key K, value V) bool) TreeMapIterator[K, V]
Find passes each element of the container to the given function and returns iterator to the first element for which the function is true. If no element matches the criteria, this returns the iterator past the last element (one-past-the-end).
func (*TreeMap[K, V]) Get ¶
Get searches the element in the map by key and returns its value or nil if key is not found in tree. Second return parameter is true if key was found, otherwise false. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*TreeMap[K, V]) Iterator ¶
func (m *TreeMap[K, V]) Iterator() TreeMapIterator[K, V]
Iterator returns a stateful iterator whose elements are key/value pairs.
func (*TreeMap[K, V]) LowerBound ¶
func (m *TreeMap[K, V]) LowerBound(key K) TreeMapIterator[K, V]
LowerBound returns an iterator pointing to the first element that is not less than key. If no such element is found, a past-the-end iterator is returned.
func (*TreeMap[K, V]) Map ¶
Map invokes the given function once for each element and returns a container containing the values returned by the given function as key/value pairs.
func (*TreeMap[K, V]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*TreeMap[K, V]) Max ¶
Max returns the maximum key and its value from the tree map. If the map is empty, the third return parameter will be false.
func (*TreeMap[K, V]) Min ¶
Min returns the minimum key and its value from the tree map. If the map is empty, the third return parameter will be false.
func (*TreeMap[K, V]) Put ¶
func (m *TreeMap[K, V]) Put(key K, value V)
Put inserts key-value pair into the map. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*TreeMap[K, V]) Remove ¶
func (m *TreeMap[K, V]) Remove(key K)
Remove removes the element from the map by key. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*TreeMap[K, V]) Select ¶
Select returns a new container containing all elements for which the given function returns a true value.
func (*TreeMap[K, V]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler
func (*TreeMap[K, V]) UpperBound ¶
func (m *TreeMap[K, V]) UpperBound(key K) TreeMapIterator[K, V]
UpperBound returns an iterator pointing to the first element that is greater than key. If no such element is found, a past-the-end iterator is returned.
type TreeMapIterator ¶
type TreeMapIterator[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
func (*TreeMapIterator[K, V]) Begin ¶
func (iterator *TreeMapIterator[K, V]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*TreeMapIterator[K, V]) End ¶
func (iterator *TreeMapIterator[K, V]) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*TreeMapIterator[K, V]) First ¶
func (iterator *TreeMapIterator[K, V]) 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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator
func (*TreeMapIterator[K, V]) IsBegin ¶
func (iterator *TreeMapIterator[K, V]) IsBegin() bool
IsBegin returns true if the iterator is in initial state (one-before-first)
func (*TreeMapIterator[K, V]) IsEnd ¶
func (iterator *TreeMapIterator[K, V]) IsEnd() bool
IsEnd returns true if the iterator is past the last element (one-past-the-end).
func (*TreeMapIterator[K, V]) Key ¶
func (iterator *TreeMapIterator[K, V]) Key() K
Key returns the current element's key. Does not modify the state of the iterator.
func (*TreeMapIterator[K, V]) Last ¶
func (iterator *TreeMapIterator[K, V]) 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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*TreeMapIterator[K, V]) Next ¶
func (iterator *TreeMapIterator[K, V]) 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 key and value can be retrieved by Key() 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 (*TreeMapIterator[K, V]) NextTo ¶
func (iterator *TreeMapIterator[K, V]) NextTo(f func(key K, value V) 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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*TreeMapIterator[K, V]) Prev ¶
func (iterator *TreeMapIterator[K, V]) 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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*TreeMapIterator[K, V]) PrevTo ¶
func (iterator *TreeMapIterator[K, V]) PrevTo(f func(key K, value V) 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 key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.
func (*TreeMapIterator[K, V]) Value ¶
func (iterator *TreeMapIterator[K, V]) Value() V
Value returns the current element's value. Does not modify the state of the iterator.