Documentation ¶
Index ¶
- Constants
- type Color
- type ConstBidIterator
- type ConstIterator
- type Entry
- type KVisitor
- type Map
- type Option
- type RBTree
- func (t *RBTree[K, V]) Begin() *Entry[K, V]
- func (t *RBTree[K, V]) Clear()
- func (t *RBTree[K, V]) Delete(node *Entry[K, V])
- func (t *RBTree[K, V]) Empty() bool
- func (t *RBTree[K, V]) FindLowerBoundNode(key K) *Entry[K, V]
- func (t *RBTree[K, V]) FindNode(key K) *Entry[K, V]
- func (t *RBTree[K, V]) FindUpperBoundNode(key K) *Entry[K, V]
- func (t *RBTree[K, V]) First() *Entry[K, V]
- func (t *RBTree[K, V]) Insert(key K, value V)
- func (t *RBTree[K, V]) IterFirst() *RBTreeIterator[K, V]
- func (t *RBTree[K, V]) IterLast() *RBTreeIterator[K, V]
- func (t *RBTree[K, V]) Last() *Entry[K, V]
- func (t *RBTree[K, V]) RBegin() *Entry[K, V]
- func (t *RBTree[K, V]) Size() int
- func (t *RBTree[K, V]) Traversal(visitor KVisitor[K, V])
- type RBTreeIterator
- func (iter *RBTreeIterator[K, V]) Clone() ConstIterator[V]
- func (iter *RBTreeIterator[K, V]) Equal(other ConstIterator[V]) bool
- func (iter *RBTreeIterator[K, V]) IsValid() bool
- func (iter *RBTreeIterator[K, V]) Key() K
- func (iter *RBTreeIterator[K, V]) Next() ConstIterator[V]
- func (iter *RBTreeIterator[K, V]) Prev() ConstBidIterator[V]
- func (iter *RBTreeIterator[K, V]) SetValue(val V) error
- func (iter *RBTreeIterator[K, V]) Value() V
Examples ¶
Constants ¶
const ( RED = false BLACK = true )
Define node 's colors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstBidIterator ¶
type ConstBidIterator[T any] interface { ConstIterator[T] Prev() ConstBidIterator[T] }
ConstBidIterator is an interface of const bidirectional iterator
type ConstIterator ¶
type ConstIterator[T any] interface { IsValid() bool Next() ConstIterator[T] Value() T Clone() ConstIterator[T] Equal(other ConstIterator[T]) bool }
ConstIterator is an interface of const iterator
type Entry ¶ added in v0.5.6
Entry is a tree entry
type Map ¶
type RBTree ¶
RBTree is a kind of self-balancing binary search tree in computer science. Each node of the binary tree has an extra bit, and that bit is often interpreted as the color (red or black) of the node. These color bits are used to ensure the tree remains approximately balanced during insertions and deletions.
func (*RBTree[K, V]) FindLowerBoundNode ¶
FindLowerBoundNode finds the first node that its key is equal or greater than the passed key, and returns it
func (*RBTree[K, V]) FindNode ¶
FindNode the first node that the key is equal to the passed key and return it
func (*RBTree[K, V]) FindUpperBoundNode ¶
FindUpperBoundNode finds the first node that its key is greater than the passed key, and returns it
func (*RBTree[K, V]) Insert ¶
func (t *RBTree[K, V]) Insert(key K, value V)
Insert inserts a key-value pair into the RBTree.
func (*RBTree[K, V]) IterFirst ¶
func (t *RBTree[K, V]) IterFirst() *RBTreeIterator[K, V]
IterFirst returns the iterator of first node
func (*RBTree[K, V]) IterLast ¶
func (t *RBTree[K, V]) IterLast() *RBTreeIterator[K, V]
IterLast returns the iterator of first node
type RBTreeIterator ¶
RBTreeIterator is an iterator implementation of RBTree
func NewIterator ¶
func NewIterator[K cmp.Ordered, V any](node *Entry[K, V]) *RBTreeIterator[K, V]
NewIterator creates a RBTreeIterator from the passed node
func (*RBTreeIterator[K, V]) Clone ¶
func (iter *RBTreeIterator[K, V]) Clone() ConstIterator[V]
Clone clones the iterator into a new RBTreeIterator
func (*RBTreeIterator[K, V]) Equal ¶
func (iter *RBTreeIterator[K, V]) Equal(other ConstIterator[V]) bool
Equal returns true if the iterator is equal to the passed iterator
func (*RBTreeIterator[K, V]) IsValid ¶
func (iter *RBTreeIterator[K, V]) IsValid() bool
IsValid returns true if the iterator is valid, otherwise returns false
func (*RBTreeIterator[K, V]) Key ¶
func (iter *RBTreeIterator[K, V]) Key() K
Key returns the node's key of the iterator point to
func (*RBTreeIterator[K, V]) Next ¶
func (iter *RBTreeIterator[K, V]) Next() ConstIterator[V]
Next moves the pointer of the iterator to the next node, and returns itself
func (*RBTreeIterator[K, V]) Prev ¶
func (iter *RBTreeIterator[K, V]) Prev() ConstBidIterator[V]
Prev moves the pointer of the iterator to the previous node, and returns itself
func (*RBTreeIterator[K, V]) SetValue ¶
func (iter *RBTreeIterator[K, V]) SetValue(val V) error
SetValue sets the node's value of the iterator point to
func (*RBTreeIterator[K, V]) Value ¶
func (iter *RBTreeIterator[K, V]) Value() V
Value returns the node's value of the iterator point to