Documentation ¶
Index ¶
- type Iterator
- func (it *Iterator[K, V]) Get() misc.Pair[K, V]
- func (it *Iterator[K, V]) Key() K
- func (it *Iterator[K, V]) Move()
- func (it *Iterator[K, V]) Node() *Node[K, V]
- func (it *Iterator[K, V]) Remove()
- func (it *Iterator[K, V]) SetValue(value V)
- func (it *Iterator[K, V]) Valid() bool
- func (it *Iterator[K, V]) Value() V
- func (it *Iterator[K, V]) ValueRef() *V
- type Node
- func (node *Node[K, V]) Clone() *Node[K, V]
- func (node *Node[K, V]) Key() K
- func (node *Node[K, V]) LeftChild() *Node[K, V]
- func (node *Node[K, V]) Max() *Node[K, V]
- func (node *Node[K, V]) Min() *Node[K, V]
- func (node *Node[K, V]) Next() *Node[K, V]
- func (node *Node[K, V]) Parent() *Node[K, V]
- func (node *Node[K, V]) Prev() *Node[K, V]
- func (node *Node[K, V]) RightChild() *Node[K, V]
- func (node *Node[K, V]) Sibling() *Node[K, V]
- type Tree
- func New[K cmp.Ordered, V any]() *Tree[K, V]
- func NewFromIterable[K cmp.Ordered, V any](iterable iter.Iterable[misc.Pair[K, V]]) *Tree[K, V]
- func NewWithComparator[K, V any](comparator comparison.Comparator[K]) *Tree[K, V]
- func NewWithComparatorFromIterable[K, V any](comparator comparison.Comparator[K], iterable iter.Iterable[misc.Pair[K, V]]) *Tree[K, V]
- func (tree *Tree[K, V]) Clear()
- func (tree *Tree[K, V]) Clone() maps.Map[K, V]
- func (tree *Tree[K, V]) Contains(key K) bool
- func (tree *Tree[K, V]) Get(key K) V
- func (tree *Tree[K, V]) GetNode(key K) *Node[K, V]
- func (tree *Tree[K, V]) GetRef(key K) *V
- func (tree *Tree[K, V]) Iterator() iter.Iterator[misc.Pair[K, V]]
- func (tree *Tree[K, V]) MapIterator() maps.Iterator[K, V]
- func (tree *Tree[K, V]) RefsStream2(yield func(K, *V) bool)
- func (tree *Tree[K, V]) Remove(key K)
- func (tree *Tree[K, V]) Root() *Node[K, V]
- func (tree *Tree[K, V]) Set(key K, value V)
- func (tree *Tree[K, V]) Size() int
- func (tree *Tree[K, V]) Stream2(yield func(K, V) bool)
- func (tree *Tree[K, V]) TryGet(key K) (V, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[K, V any] struct { // contains filtered or unexported fields }
Iterator is an iterator over a Tree.
func (*Iterator[K, V]) Key ¶
func (it *Iterator[K, V]) Key() K
Key returns the key of the current entry.
func (*Iterator[K, V]) Move ¶
func (it *Iterator[K, V]) Move()
Move moves the iterator to the next entry.
func (*Iterator[K, V]) Remove ¶
func (it *Iterator[K, V]) Remove()
Remove removes the current entry from the map. The iterator will point to the next entry afterward.
func (*Iterator[K, V]) SetValue ¶
func (it *Iterator[K, V]) SetValue(value V)
SetValue sets the value of the current entry.
type Node ¶
type Node[K, V any] struct { Value V // Value is the value stored in the node. // contains filtered or unexported fields }
Node is a node of a red-black tree. It should not be created directly.
func (*Node[K, V]) Clone ¶
Clone returns a clone of the node. The clone has the same key, value, and color as the node. The clone does not have any links to other nodes.
func (*Node[K, V]) RightChild ¶
RightChild returns the right child of the node.
type Tree ¶
type Tree[K, V any] struct { // contains filtered or unexported fields }
Tree is a red-black tree implementation of a map. The zero value is ready to use. Do not copy a non-zero Tree.
func NewFromIterable ¶ added in v1.6.1
NewFromIterable creates a Tree from the specified iter.Iterable.
func NewWithComparator ¶
func NewWithComparator[K, V any](comparator comparison.Comparator[K]) *Tree[K, V]
NewWithComparator creates an empty Tree with the specified comparator.
func NewWithComparatorFromIterable ¶ added in v1.6.1
func NewWithComparatorFromIterable[K, V any](comparator comparison.Comparator[K], iterable iter.Iterable[misc.Pair[K, V]]) *Tree[K, V]
NewWithComparatorFromIterable creates a Tree with the specified comparator from the specified iter.Iterable.
func (*Tree[K, V]) Get ¶
func (tree *Tree[K, V]) Get(key K) V
Get returns the value associated with the specified key. Panics if the key is not present.
func (*Tree[K, V]) GetNode ¶
GetNode returns the node associated with the specified key. Returns nil if the key is not present.
func (*Tree[K, V]) GetRef ¶
func (tree *Tree[K, V]) GetRef(key K) *V
GetRef returns a reference to the value associated with the specified key. Panics if the key is not present.
func (*Tree[K, V]) MapIterator ¶
MapIterator returns an iterator over the tree.
func (*Tree[K, V]) RefsStream2 ¶ added in v1.7.0
RefsStream2 streams over the keys and references to the values in the Map.
func (*Tree[K, V]) Remove ¶
func (tree *Tree[K, V]) Remove(key K)
Remove removes the entry with the specified key. Does nothing if the key is not present.
func (*Tree[K, V]) Set ¶
func (tree *Tree[K, V]) Set(key K, value V)
Set sets the value associated with the specified key.