Documentation ¶
Index ¶
- func Comparator[K OrderKey](a, b K) int
- func ToString(value interface{}) string
- type IMap
- type Iterator
- type Map
- func (m *Map[K, V]) Ceiling(key K) (ceiling *Node[K, V], found bool)
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Empty() bool
- func (m *Map[K, V]) Floor(key K) (floor *Node[K, V], found bool)
- func (tree *Map[K, V]) FromJSON(data []byte) error
- func (m *Map[K, V]) Get(key K) (value V, found bool)
- func (it *Map[K, V]) Iterator() Iterator[K, V]
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Left() *Node[K, V]
- func (m *Map[K, V]) Put(key K, value V)
- func (m *Map[K, V]) Remove(key K)
- func (m *Map[K, V]) Right() *Node[K, V]
- func (m *Map[K, V]) Size() int
- func (m *Map[K, V]) String() string
- func (tree *Map[K, V]) ToJSON() ([]byte, error)
- func (m *Map[K, V]) Values() []V
- type Node
- type OrderKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Comparator ¶ added in v1.9.9
IntComparator provides a basic comparison on int
Types ¶
type Iterator ¶
Iterator holding the iterator's state
func (*Iterator[K, V]) Begin ¶
func (it *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 (it *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 (it *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.
type Map ¶
type Map[K OrderKey, V any] struct { Root *Node[K, V] Nil V // contains filtered or unexported fields }
Map holds elements of the red-black tree
func (*Map[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 (*Map[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 (*Map[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 (*Map[K, V]) Iterator ¶
Iterator returns a stateful iterator whose elements are key/value pairs.
func (*Map[K, V]) Put ¶
func (m *Map[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 (*Map[K, V]) Remove ¶
func (m *Map[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.