Documentation ¶
Index ¶
- type Node
- func (o *Node[K, V]) IsRed() bool
- func (o *Node[K, V]) Key() K
- func (o *Node[K, V]) KeyValue() (K, V)
- func (o *Node[K, V]) Max() (node *Node[K, V])
- func (o *Node[K, V]) Min() (node *Node[K, V])
- func (o *Node[K, V]) Range(f func(o *Node[K, V]) bool)
- func (o *Node[K, V]) Size() int
- func (o *Node[K, V]) String() string
- type Option
- type Tree
- func (t *Tree[K, V]) Between(left, right K, f func(o *Node[K, V]))
- func (t *Tree[K, V]) Ceil(key K) (ceil *Node[K, V])
- func (t *Tree[K, V]) Delete(key K)
- func (t *Tree[K, V]) Floor(key K) (floor *Node[K, V])
- func (t *Tree[K, V]) Get(key K) *Node[K, V]
- func (t *Tree[K, V]) Keys() []K
- func (t *Tree[K, V]) Max() *Node[K, V]
- func (t *Tree[K, V]) Min() *Node[K, V]
- func (t *Tree[K, V]) Put(key K, value V) (isNew bool)
- func (t *Tree[K, V]) Range(f func(o *Node[K, V]) bool)
- func (t *Tree[K, V]) Root() *Node[K, V]
- func (t *Tree[K, V]) Size() int
- func (t *Tree[K, V]) String() string
- func (t *Tree[K, V]) Update(key K, value V)
- func (t *Tree[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node[K cmp.Ordered, V any] struct { Left *Node[K, V] Right *Node[K, V] Value V // contains filtered or unexported fields }
type Tree ¶
Tree 实现了左倾红黑树,左倾红黑树是 2-3树在二叉树上的转换,因此 2-3 树与左倾红黑树是等价的。
func NewIntTree ¶
NewIntTree 初始化 int 类型的左倾红黑树,参数 opts 用于修改红黑树的配置
目前可以修改的配置有 1. upsert 字段用于 Put 操作时,如何更新已存在节点的 Value,默认情况下会替换为输入的 value
func NewStringTree ¶
NewStringTree 初始化 string 类型的左倾红黑树,参数 opts 用于修改红黑树的配置
目前可以修改的配置有 1. upsert 字段用于 Put 操作时,如何更新已存在节点的 Value,默认情况下会替换为输入的 value
func NewTree ¶
NewTree 初始化左倾红黑树,参数 opts 用于修改红黑树的配置
目前可以修改的配置有 1. upsert 字段用于 Put 操作时,如何更新已存在节点的 Value,默认情况下会替换为输入的 value
func (*Tree[K, V]) Ceil ¶
Ceil 寻找给定 key的 ceil 节点,ceil 节点定义为:在大于等于 key 节点中的最小值 如果 ceil 为 nil,则意味着树是空的,或者树中所有元素都小于 key
func (*Tree[K, V]) Delete ¶
func (t *Tree[K, V]) Delete(key K)
Delete 从树中删除指定 key 的节点,如果节点不存在,那么什么也不做
func (*Tree[K, V]) Floor ¶
Floor 寻找给定 key 的 floor 节点,floor 节点定义为:在小于等于 key 节点中的最大值, 如果 floor 为 nil,则意味着树是空的,或者树中所有元素都大于 key。
func (*Tree[K, V]) Put ¶
Put 向树中插入新的节点,如果节点已存在,则按照 t.upsert 更新节点值 t.upsert 默认情况,节点 *Node.Value 会替换为输入的 value