gtree

原文:https://pkg.go.dev/github.com/gogf/gf/v2@v2.6.4/container/gtree

Package gtree provides concurrent-safe/unsafe tree containers.

​ 软件包 gtree 提供了并发安全/不安全的树容器。

Some implements are from: https://github.com/emirpasic/gods

​ 一些工具来自:https://github.com/emirpasic/gods

常量

This section is empty.

变量

This section is empty.

函数

This section is empty.

类型

type AVLTree

1
2
3
type AVLTree struct {
	// contains filtered or unexported fields
}

AVLTree holds elements of the AVL tree.

​ AVLTree 保存 AVL 树的元素。

func NewAVLTree

1
func NewAVLTree(comparator func(v1, v2 interface{}) int, safe ...bool) *AVLTree

NewAVLTree instantiates an AVL tree with the custom key comparator. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default.

​ NewAVLTree 使用自定义密钥比较器实例化 AVL 树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。

Example

func NewAVLTreeFrom

1
func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *AVLTree

NewAVLTreeFrom instantiates an AVL tree with the custom key comparator and data map. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default.

​ NewAVLTreeFrom 使用自定义键比较器和数据映射实例化 AVL 树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。

Example

(*AVLTree) Ceiling

1
func (tree *AVLTree) Ceiling(key interface{}) (ceiling *AVLTreeNode, found bool)

Ceiling finds ceiling node of the input key, return the ceiling node or nil if no ceiling node is found. Second return parameter is true if ceiling was found, otherwise false.

​ ceiling 查找输入键的 ceiling 节点,返回 ceiling 节点,如果没有找到 ceiling 节点,则返回 nil。如果找到 ceiling,则第二个返回参数为 true,否则为 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 is smaller than the given node.

​ 天花板节点定义为大于或等于给定节点的最小节点。可能找不到天花板节点,因为树为空,或者树中的所有节点都小于给定节点。

Key should adhere to the comparator’s type assertion, otherwise method panics.

​ 键应遵循比较器的类型断言,否则方法会崩溃。

Example

(*AVLTree) Clear

1
func (tree *AVLTree) Clear()

Clear removes all nodes from the tree.

​ 清除将从树中删除所有节点。

Example

(*AVLTree) Clone

1
func (tree *AVLTree) Clone() *AVLTree

Clone returns a new tree with a copy of current tree.

​ 克隆返回一个新树,其中包含当前树的副本。

Example

(*AVLTree) Contains

1
func (tree *AVLTree) Contains(key interface{}) bool

Contains checks whether key exists in the tree.

​ 包含检查树中是否 key 存在。

Example

(*AVLTree) Flip

1
func (tree *AVLTree) Flip(comparator ...func(v1, v2 interface{}) int)

Flip exchanges key-value of the tree to value-key. Note that you should guarantee the value is the same type as key, or else the comparator would panic.

​ Flip 将树的键值交换为值键。请注意,应保证该值与键的类型相同,否则比较器会崩溃。

If the type of value is different with key, you pass the new comparator.

​ 如果值的类型与键不同,则传递新的 comparator .

Example

(*AVLTree) Floor

1
func (tree *AVLTree) Floor(key interface{}) (floor *AVLTreeNode, found bool)

Floor Finds floor node of the input key, return the floor node or nil if no floor node is found. Second return parameter is true if floor was found, otherwise false.

​ Floor 查找输入键的 floor 节点,返回 floor 节点,如果没有找到 floor 节点,则返回 nil。如果找到 floor,则第二个返回参数为 true,否则为 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 is larger than the given node.

​ 地板节点定义为小于或等于给定节点的最大节点。可能找不到楼层节点,因为树为空,或者树中的所有节点都大于给定节点。

Key should adhere to the comparator’s type assertion, otherwise method panics.

​ 键应遵循比较器的类型断言,否则方法会崩溃。

Example

(*AVLTree) Get

1
func (tree *AVLTree) Get(key interface{}) (value interface{})

Get searches the node in the tree by key and returns its value or nil if key is not found in tree.

​ Get 搜索树 key 中的节点,如果在树中找不到键,则返回其值或 nil。

Example

(*AVLTree) GetOrSet

1
func (tree *AVLTree) GetOrSet(key interface{}, value interface{}) interface{}

GetOrSet returns the value by key, or sets value with given value if it does not exist and then returns this value.

​ GetOrSet 按键返回值,如果值不存在,则使用 given value 设置值,然后返回此值。

Example

(*AVLTree) GetOrSetFunc

1
func (tree *AVLTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFunc 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

Example

(*AVLTree) GetOrSetFuncLock

1
func (tree *AVLTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFuncLock 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function f with mutex.Lock of the hash map.

​ GetOrSetFuncLock 与 GetOrSetFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*AVLTree) GetVar

1
func (tree *AVLTree) GetVar(key interface{}) *gvar.Var

GetVar returns a gvar.Var with the value by given key. The returned gvar.Var is un-concurrent safe.

​ GetVar 返回一个 gvar。Var 的值由 给定 key 。返回的 gvar。Var 是非并发安全的。

Example

(*AVLTree) GetVarOrSet

1
func (tree *AVLTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSet 返回 gvar。具有 GetVarOrSet 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*AVLTree) GetVarOrSetFunc

1
func (tree *AVLTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFunc 返回 gvar。具有 GetOrSetFunc 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*AVLTree) GetVarOrSetFuncLock

1
func (tree *AVLTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFuncLock 返回 gvar。具有 GetOrSetFuncLock 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*AVLTree) IsEmpty

1
func (tree *AVLTree) IsEmpty() bool

IsEmpty returns true if tree does not contain any nodes.

​ 如果树不包含任何节点,则 IsEmpty 返回 true。

Example

(*AVLTree) Iterator

1
func (tree *AVLTree) Iterator(f func(key, value interface{}) bool)

Iterator is alias of IteratorAsc.

​ Iterator 是 IteratorAsc 的别名。

Example

(*AVLTree) IteratorAsc

1
func (tree *AVLTree) IteratorAsc(f func(key, value interface{}) bool)

IteratorAsc iterates the tree readonly in ascending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorAsc 使用给定的回调函数 f 按升序迭代树只读。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*AVLTree) IteratorAscFrom

1
func (tree *AVLTree) IteratorAscFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorAscFrom iterates the tree readonly in ascending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorAscFrom 使用给定的回调函数 f 按升序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

(*AVLTree) IteratorDesc

1
func (tree *AVLTree) IteratorDesc(f func(key, value interface{}) bool)

IteratorDesc iterates the tree readonly in descending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorDesc 使用给定的回调函数 f 按降序只读迭代树。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*AVLTree) IteratorDescFrom

1
func (tree *AVLTree) IteratorDescFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorDescFrom iterates the tree readonly in descending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorDescFrom 使用给定的回调函数 f 按降序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*AVLTree) IteratorFrom

1
func (tree *AVLTree) IteratorFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorFrom is alias of IteratorAscFrom.

​ IteratorFrom 是 IteratorAscFrom 的别名。

Example

(*AVLTree) Keys

1
func (tree *AVLTree) Keys() []interface{}

Keys returns all keys in asc order.

​ Keys 按 asc 顺序返回所有键。

Example

(*AVLTree) Left

1
func (tree *AVLTree) Left() *AVLTreeNode

Left returns the minimum element of the AVL tree or nil if the tree is empty.

​ Left 返回 AVL 树的最小元素,如果树为空,则返回 nil。

Example

(*AVLTree) Map

1
func (tree *AVLTree) Map() map[interface{}]interface{}

Map returns all key-value items as map.

​ Map 以 map 的形式返回所有键值项。

Example

(*AVLTree) MapStrAny

1
func (tree *AVLTree) MapStrAny() map[string]interface{}

MapStrAny returns all key-value items as map[string]interface{}.

​ MapStrAny 以 map[string]interface{} 的形式返回所有键值项。

Example

(AVLTree) MarshalJSON

1
func (tree AVLTree) MarshalJSON() (jsonBytes []byte, err error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

​ MarshalJSON 实现 json 的接口 MarshalJSON。元帅。

Example

(*AVLTree) Print

1
func (tree *AVLTree) Print()

Print prints the tree to stdout.

​ 打印 将树打印到 stdout。

Example

(*AVLTree) Remove

1
func (tree *AVLTree) Remove(key interface{}) (value interface{})

Remove removes the node from the tree by key. Key should adhere to the comparator’s type assertion, otherwise method panics.

​ Remove 按键从树中删除节点。键应遵循比较器的类型断言,否则方法会崩溃。

Example

(*AVLTree) Removes

1
func (tree *AVLTree) Removes(keys []interface{})

Removes batch deletes values of the tree by keys.

​ 删除 batch 删除树 keys 的值。

Example

(*AVLTree) Replace

1
func (tree *AVLTree) Replace(data map[interface{}]interface{})

Replace the data of the tree with given data.

​ 将树的数据替换为 给定 data 的 .

Example

(*AVLTree) Right

1
func (tree *AVLTree) Right() *AVLTreeNode

Right returns the maximum element of the AVL tree or nil if the tree is empty.

​ Right 返回 AVL 树的最大元素,如果树为空,则返回 nil。

Example
1
func (tree *AVLTree) Search(key interface{}) (value interface{}, found bool)

Search searches the tree with given key. Second return parameter found is true if key was found, otherwise false.

​ 搜索 使用给定 key 的树搜索 。如果找到键,则第二个返回参数 found 为 true,否则为 false。

Example

(*AVLTree) Set

1
func (tree *AVLTree) Set(key interface{}, value interface{})

Set inserts node into the tree.

​ 将插入节点设置到树中。

Example

(*AVLTree) SetIfNotExist

1
func (tree *AVLTree) SetIfNotExist(key interface{}, value interface{}) bool

SetIfNotExist sets value to the map if the key does not exist, and then returns true. It returns false if key exists, and value would be ignored.

​ 如果 不存在 key ,则 SetIfNotExist 设置为 value 映射,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*AVLTree) SetIfNotExistFunc

1
func (tree *AVLTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool

SetIfNotExistFunc sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFunc 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*AVLTree) SetIfNotExistFuncLock

1
func (tree *AVLTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFuncLock 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function f with mutex.Lock of the hash map.

​ SetIfNotExistFuncLock 与 SetIfNotExistFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*AVLTree) Sets

1
func (tree *AVLTree) Sets(data map[interface{}]interface{})

Sets batch sets key-values to the tree.

​ 将批处理设置树的键值。

Example

(*AVLTree) Size

1
func (tree *AVLTree) Size() int

Size returns number of nodes in the tree.

​ size 返回树中的节点数。

Example

(*AVLTree) String

1
func (tree *AVLTree) String() string

String returns a string representation of container

​ String 返回容器的字符串表示形式

Example

(*AVLTree) Values

1
func (tree *AVLTree) Values() []interface{}

Values returns all values in asc order based on the key.

​ Values 根据键按 asc 顺序返回所有值。

Example

type AVLTreeNode

1
2
3
4
5
type AVLTreeNode struct {
	Key   interface{}
	Value interface{}
	// contains filtered or unexported fields
}

AVLTreeNode is a single element within the tree.

​ AVLTreeNode 是树中的单个元素。

(*AVLTreeNode) Next

1
func (node *AVLTreeNode) Next() *AVLTreeNode

Next returns the next element in an inorder walk of the AVL tree.

​ Next 返回 AVL 树的无序游历中的下一个元素。

(*AVLTreeNode) Prev

1
func (node *AVLTreeNode) Prev() *AVLTreeNode

Prev returns the previous element in an inorder walk of the AVL tree.

​ Prev 返回 AVL 树的无序遍历中的前一个元素。

type BTree

1
2
3
type BTree struct {
	// contains filtered or unexported fields
}

BTree holds elements of the B-tree.

​ BTree 包含 B 树的元素。

func NewBTree

1
func NewBTree(m int, comparator func(v1, v2 interface{}) int, safe ...bool) *BTree

NewBTree instantiates a B-tree with m (maximum number of children) and a custom key comparator. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default. Note that the m must be greater or equal than 3, or else it panics.

​ NewBTree 实例化具有 m (最大子项数)和自定义键比较器的 B 树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。请注意,必须 m 大于或等于 3,否则会出现恐慌。

Example

func NewBTreeFrom

1
func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *BTree

NewBTreeFrom instantiates a B-tree with m (maximum number of children), a custom key comparator and data map. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default.

​ NewBTreeFrom 实例化具有 m (最大子项数)、自定义键比较器和数据映射的 B 树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。

Example

(*BTree) Clear

1
func (tree *BTree) Clear()

Clear removes all nodes from the tree.

​ 清除将从树中删除所有节点。

Example

(*BTree) Clone

1
func (tree *BTree) Clone() *BTree

Clone returns a new tree with a copy of current tree.

​ 克隆返回一个新树,其中包含当前树的副本。

Example

(*BTree) Contains

1
func (tree *BTree) Contains(key interface{}) bool

Contains checks whether key exists in the tree.

​ 包含检查树中是否 key 存在。

Example

(*BTree) Get

1
func (tree *BTree) Get(key interface{}) (value interface{})

Get searches the node in the tree by key and returns its value or nil if key is not found in tree.

​ Get 搜索树 key 中的节点,如果在树中找不到键,则返回其值或 nil。

Example

(*BTree) GetOrSet

1
func (tree *BTree) GetOrSet(key interface{}, value interface{}) interface{}

GetOrSet returns the value by key, or sets value with given value if it does not exist and then returns this value.

​ GetOrSet 按键返回值,如果值不存在,则使用 given value 设置值,然后返回此值。

Example

(*BTree) GetOrSetFunc

1
func (tree *BTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFunc 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

Example

(*BTree) GetOrSetFuncLock

1
func (tree *BTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFuncLock 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function f with mutex.Lock of the hash map.

​ GetOrSetFuncLock 与 GetOrSetFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*BTree) GetVar

1
func (tree *BTree) GetVar(key interface{}) *gvar.Var

GetVar returns a gvar.Var with the value by given key. The returned gvar.Var is un-concurrent safe.

​ GetVar 返回一个 gvar。Var 的值由 给定 key 。返回的 gvar。Var 是非并发安全的。

Example

(*BTree) GetVarOrSet

1
func (tree *BTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSet 返回 gvar。具有 GetVarOrSet 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*BTree) GetVarOrSetFunc

1
func (tree *BTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFunc 返回 gvar。具有 GetOrSetFunc 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*BTree) GetVarOrSetFuncLock

1
func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFuncLock 返回 gvar。具有 GetOrSetFuncLock 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*BTree) Height

1
func (tree *BTree) Height() int

Height returns the height of the tree.

​ Height 返回树的高度。

Example

(*BTree) IsEmpty

1
func (tree *BTree) IsEmpty() bool

IsEmpty returns true if tree does not contain any nodes

​ 如果树不包含任何节点,则 IsEmpty 返回 true

Example

(*BTree) Iterator

1
func (tree *BTree) Iterator(f func(key, value interface{}) bool)

Iterator is alias of IteratorAsc.

​ Iterator 是 IteratorAsc 的别名。

Example

(*BTree) IteratorAsc

1
func (tree *BTree) IteratorAsc(f func(key, value interface{}) bool)

IteratorAsc iterates the tree readonly in ascending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorAsc 使用给定的回调函数 f 按升序迭代树只读。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*BTree) IteratorAscFrom

1
func (tree *BTree) IteratorAscFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorAscFrom iterates the tree readonly in ascending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorAscFrom 使用给定的回调函数 f 按升序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

(*BTree) IteratorDesc

1
func (tree *BTree) IteratorDesc(f func(key, value interface{}) bool)

IteratorDesc iterates the tree readonly in descending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorDesc 使用给定的回调函数 f 按降序只读迭代树。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*BTree) IteratorDescFrom

1
func (tree *BTree) IteratorDescFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorDescFrom iterates the tree readonly in descending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorDescFrom 使用给定的回调函数 f 按降序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*BTree) IteratorFrom

1
func (tree *BTree) IteratorFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorFrom is alias of IteratorAscFrom.

​ IteratorFrom 是 IteratorAscFrom 的别名。

Example

(*BTree) Keys

1
func (tree *BTree) Keys() []interface{}

Keys returns all keys in asc order.

​ Keys 按 asc 顺序返回所有键。

Example

(*BTree) Left

1
func (tree *BTree) Left() *BTreeEntry

Left returns the left-most (min) entry or nil if tree is empty.

​ Left 返回最左边的 (min) 条目,如果 tree 为空,则返回 nil。

Example

(*BTree) Map

1
func (tree *BTree) Map() map[interface{}]interface{}

Map returns all key-value items as map.

​ Map 以 map 的形式返回所有键值项。

Example

(*BTree) MapStrAny

1
func (tree *BTree) MapStrAny() map[string]interface{}

MapStrAny returns all key-value items as map[string]interface{}.

​ MapStrAny 以 map[string]interface{} 的形式返回所有键值项。

Example

(BTree) MarshalJSON

1
func (tree BTree) MarshalJSON() (jsonBytes []byte, err error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

​ MarshalJSON 实现 json 的接口 MarshalJSON。元帅。

Example

(*BTree) Print

1
func (tree *BTree) Print()

Print prints the tree to stdout.

​ 打印 将树打印到 stdout。

Example

(*BTree) Remove

1
func (tree *BTree) Remove(key interface{}) (value interface{})

Remove removes the node from the tree by key.

​ Remove 通过 key 从树中删除节点。

Example

(*BTree) Removes

1
func (tree *BTree) Removes(keys []interface{})

Removes batch deletes values of the tree by keys.

​ 删除 batch 删除树 keys 的值。

Example

(*BTree) Replace

1
func (tree *BTree) Replace(data map[interface{}]interface{})

Replace the data of the tree with given data.

​ 将树的数据替换为 给定 data 的 .

Example

(*BTree) Right

1
func (tree *BTree) Right() *BTreeEntry

Right returns the right-most (max) entry or nil if tree is empty.

​ 如果树为空,则 Right 返回最右边 (max) 的条目或 nil。

Example
1
func (tree *BTree) Search(key interface{}) (value interface{}, found bool)

Search searches the tree with given key. Second return parameter found is true if key was found, otherwise false.

​ 搜索 使用给定 key 的树搜索 。如果找到键,则第二个返回参数 found 为 true,否则为 false。

Example

(*BTree) Set

1
func (tree *BTree) Set(key interface{}, value interface{})

Set inserts key-value item into the tree.

​ Set 将键值项插入到树中。

Example

(*BTree) SetIfNotExist

1
func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool

SetIfNotExist sets value to the map if the key does not exist, and then returns true. It returns false if key exists, and value would be ignored.

​ 如果 不存在 key ,则 SetIfNotExist 设置为 value 映射,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*BTree) SetIfNotExistFunc

1
func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool

SetIfNotExistFunc sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFunc 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*BTree) SetIfNotExistFuncLock

1
func (tree *BTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFuncLock 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function f with mutex.Lock of the hash map.

​ SetIfNotExistFuncLock 与 SetIfNotExistFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*BTree) Sets

1
func (tree *BTree) Sets(data map[interface{}]interface{})

Sets batch sets key-values to the tree.

​ 将批处理设置树的键值。

Example

(*BTree) Size

1
func (tree *BTree) Size() int

Size returns number of nodes in the tree.

​ size 返回树中的节点数。

Example

(*BTree) String

1
func (tree *BTree) String() string

String returns a string representation of container (for debugging purposes)

​ String 返回容器的字符串表示形式(用于调试目的)

Example

(*BTree) Values

1
func (tree *BTree) Values() []interface{}

Values returns all values in asc order based on the key.

​ Values 根据键按 asc 顺序返回所有值。

Example

type BTreeEntry

1
2
3
4
type BTreeEntry struct {
	Key   interface{}
	Value interface{}
}

BTreeEntry represents the key-value pair contained within nodes.

​ BTreeEntry 表示节点中包含的键值对。

type BTreeNode

1
2
3
4
5
type BTreeNode struct {
	Parent   *BTreeNode
	Entries  []*BTreeEntry // Contained keys in node
	Children []*BTreeNode  // Children nodes
}

BTreeNode is a single element within the tree.

​ BTreeNode 是树中的单个元素。

type RedBlackTree

1
2
3
type RedBlackTree struct {
	// contains filtered or unexported fields
}

RedBlackTree holds elements of the red-black tree.

​ RedBlackTree 包含红黑树的元素。

func NewRedBlackTree

1
func NewRedBlackTree(comparator func(v1, v2 interface{}) int, safe ...bool) *RedBlackTree

NewRedBlackTree instantiates a red-black tree with the custom key comparator. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default.

​ NewRedBlackTree 使用自定义键比较器实例化红黑树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。

Example

func NewRedBlackTreeFrom

1
func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *RedBlackTree

NewRedBlackTreeFrom instantiates a red-black tree with the custom key comparator and data map. The parameter safe is used to specify whether using tree in concurrent-safety, which is false in default.

​ NewRedBlackTreeFrom 使用自定义键比较器和 data 映射实例化红黑树。该参数 safe 用于指定是否在 concurrent-safety 中使用 tree,默认为 false。

Example

(*RedBlackTree) Ceiling

1
func (tree *RedBlackTree) Ceiling(key interface{}) (ceiling *RedBlackTreeNode, found bool)

Ceiling finds ceiling node of the input key, return the ceiling node or nil if no ceiling node is found. Second return parameter is true if ceiling was found, otherwise false.

​ ceiling 查找输入键的 ceiling 节点,返回 ceiling 节点,如果没有找到 ceiling 节点,则返回 nil。如果找到 ceiling,则第二个返回参数为 true,否则为 false。

Ceiling node is defined as the smallest node that its key is larger than or equal to the given key. 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 的最小节点。可能找不到天花板节点,因为树是空的,或者树中的所有节点都小于给定节点。

Example

(*RedBlackTree) Clear

1
func (tree *RedBlackTree) Clear()

Clear removes all nodes from the tree.

​ 清除将从树中删除所有节点。

Example

(*RedBlackTree) Clone

1
func (tree *RedBlackTree) Clone() *RedBlackTree

Clone returns a new tree with a copy of current tree.

​ 克隆返回一个新树,其中包含当前树的副本。

Example

(*RedBlackTree) Contains

1
func (tree *RedBlackTree) Contains(key interface{}) bool

Contains checks whether key exists in the tree.

​ 包含检查树中是否 key 存在。

Example

(*RedBlackTree) Flip

1
func (tree *RedBlackTree) Flip(comparator ...func(v1, v2 interface{}) int)

Flip exchanges key-value of the tree to value-key. Note that you should guarantee the value is the same type as key, or else the comparator would panic.

​ Flip 将树的键值交换为值键。请注意,应保证该值与键的类型相同,否则比较器会崩溃。

If the type of value is different with key, you pass the new comparator.

​ 如果值的类型与键不同,则传递新的 comparator .

Example

(*RedBlackTree) Floor

1
func (tree *RedBlackTree) Floor(key interface{}) (floor *RedBlackTreeNode, found bool)

Floor Finds floor node of the input key, return the floor node or nil if no floor node is found. Second return parameter is true if floor was found, otherwise false.

​ Floor 查找输入键的 floor 节点,返回 floor 节点,如果没有找到 floor 节点,则返回 nil。如果找到 floor,则第二个返回参数为 true,否则为 false。

Floor node is defined as the largest node that its key is smaller than or equal to the given key. 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.

​ Floor 节点定义为其键小于或等于给定 key 的最大节点。可能找不到楼层节点,因为树为空,或者树中的所有节点都大于给定节点。

Example

(*RedBlackTree) Get

1
func (tree *RedBlackTree) Get(key interface{}) (value interface{})

Get searches the node in the tree by key and returns its value or nil if key is not found in tree.

​ Get 搜索树 key 中的节点,如果在树中找不到键,则返回其值或 nil。

Example

(*RedBlackTree) GetOrSet

1
func (tree *RedBlackTree) GetOrSet(key interface{}, value interface{}) interface{}

GetOrSet returns the value by key, or sets value with given value if it does not exist and then returns this value.

​ GetOrSet 按键返回值,如果值不存在,则使用 given value 设置值,然后返回此值。

Example

(*RedBlackTree) GetOrSetFunc

1
func (tree *RedBlackTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFunc 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

Example

(*RedBlackTree) GetOrSetFuncLock

1
func (tree *RedBlackTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function f if it does not exist and then returns this value.

​ GetOrSetFuncLock 按键返回值,或者使用回调函数 f 的返回值设置值(如果不存在),然后返回此值。

GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function f with mutex.Lock of the hash map.

​ GetOrSetFuncLock 与 GetOrSetFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*RedBlackTree) GetVar

1
func (tree *RedBlackTree) GetVar(key interface{}) *gvar.Var

GetVar returns a gvar.Var with the value by given key. The returned gvar.Var is un-concurrent safe.

​ GetVar 返回一个 gvar。Var 的值由 给定 key 。返回的 gvar。Var 是非并发安全的。

Example

(*RedBlackTree) GetVarOrSet

1
func (tree *RedBlackTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSet 返回 gvar。具有 GetVarOrSet 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*RedBlackTree) GetVarOrSetFunc

1
func (tree *RedBlackTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFunc 返回 gvar。具有 GetOrSetFunc 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*RedBlackTree) GetVarOrSetFuncLock

1
func (tree *RedBlackTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

​ GetVarOrSetFuncLock 返回 gvar。具有 GetOrSetFuncLock 结果的 Var。返回的 gvar。Var 是非并发安全的。

Example

(*RedBlackTree) IsEmpty

1
func (tree *RedBlackTree) IsEmpty() bool

IsEmpty returns true if tree does not contain any nodes.

​ 如果树不包含任何节点,则 IsEmpty 返回 true。

Example

(*RedBlackTree) Iterator

1
func (tree *RedBlackTree) Iterator(f func(key, value interface{}) bool)

Iterator is alias of IteratorAsc.

​ Iterator 是 IteratorAsc 的别名。

Example

(*RedBlackTree) IteratorAsc

1
func (tree *RedBlackTree) IteratorAsc(f func(key, value interface{}) bool)

IteratorAsc iterates the tree readonly in ascending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorAsc 使用给定的回调函数 f 按升序迭代树只读。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*RedBlackTree) IteratorAscFrom

1
func (tree *RedBlackTree) IteratorAscFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorAscFrom iterates the tree readonly in ascending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorAscFrom 使用给定的回调函数 f 按升序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

(*RedBlackTree) IteratorDesc

1
func (tree *RedBlackTree) IteratorDesc(f func(key, value interface{}) bool)

IteratorDesc iterates the tree readonly in descending order with given callback function f. If f returns true, then it continues iterating; or false to stop.

​ IteratorDesc 使用给定的回调函数 f 按降序只读迭代树。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*RedBlackTree) IteratorDescFrom

1
func (tree *RedBlackTree) IteratorDescFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorDescFrom iterates the tree readonly in descending order with given callback function f. The parameter key specifies the start entry for iterating. The match specifies whether starting iterating if the key is fully matched, or else using index searching iterating. If f returns true, then it continues iterating; or false to stop.

​ IteratorDescFrom 使用给定的回调函数 f 按降序迭代树只读。该参数 key 指定用于迭代的开始条目。指定 match 在完全 key 匹配时是开始迭代,还是使用索引搜索迭代。如果 f 返回 true,则继续迭代;或 false 停止。

Example

(*RedBlackTree) IteratorFrom

1
func (tree *RedBlackTree) IteratorFrom(key interface{}, match bool, f func(key, value interface{}) bool)

IteratorFrom is alias of IteratorAscFrom.

​ IteratorFrom 是 IteratorAscFrom 的别名。

Example

(*RedBlackTree) Keys

1
func (tree *RedBlackTree) Keys() []interface{}

Keys returns all keys in asc order.

​ Keys 按 asc 顺序返回所有键。

Example

(*RedBlackTree) Left

1
func (tree *RedBlackTree) Left() *RedBlackTreeNode

Left returns the left-most (min) node or nil if tree is empty.

​ 如果树为空,则 left 返回最左边的 (min) 节点或 nil。

Example

(*RedBlackTree) Map

1
func (tree *RedBlackTree) Map() map[interface{}]interface{}

Map returns all key-value items as map.

​ Map 以 map 的形式返回所有键值项。

Example

(*RedBlackTree) MapStrAny

1
func (tree *RedBlackTree) MapStrAny() map[string]interface{}

MapStrAny returns all key-value items as map[string]interface{}.

​ MapStrAny 以 map[string]interface{} 的形式返回所有键值项。

Example

(RedBlackTree) MarshalJSON

1
func (tree RedBlackTree) MarshalJSON() (jsonBytes []byte, err error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

​ MarshalJSON 实现 json 的接口 MarshalJSON。元帅。

Example

(*RedBlackTree) Print

1
func (tree *RedBlackTree) Print()

Print prints the tree to stdout.

​ 打印 将树打印到 stdout。

Example

(*RedBlackTree) Remove

1
func (tree *RedBlackTree) Remove(key interface{}) (value interface{})

Remove removes the node from the tree by key.

​ Remove 通过 key 从树中删除节点。

Example

(*RedBlackTree) Removes

1
func (tree *RedBlackTree) Removes(keys []interface{})

Removes batch deletes values of the tree by keys.

​ 删除 batch 删除树 keys 的值。

Example

(*RedBlackTree) Replace

1
func (tree *RedBlackTree) Replace(data map[interface{}]interface{})

Replace the data of the tree with given data.

​ 将树的数据替换为 给定 data 的 .

Example

(*RedBlackTree) Right

1
func (tree *RedBlackTree) Right() *RedBlackTreeNode

Right returns the right-most (max) node or nil if tree is empty.

​ 如果 tree 为空,则 Right 返回最右边的 (max) 节点或 nil。

Example
1
func (tree *RedBlackTree) Search(key interface{}) (value interface{}, found bool)

Search searches the tree with given key. Second return parameter found is true if key was found, otherwise false.

​ 搜索 使用给定 key 的树搜索 。如果找到键,则第二个返回参数 found 为 true,否则为 false。

Example

(*RedBlackTree) Set

1
func (tree *RedBlackTree) Set(key interface{}, value interface{})

Set inserts key-value item into the tree.

​ Set 将键值项插入到树中。

Example

(*RedBlackTree) SetComparator

1
func (tree *RedBlackTree) SetComparator(comparator func(a, b interface{}) int)

SetComparator sets/changes the comparator for sorting.

​ SetComparator 设置/更改用于排序的比较器。

Example

(*RedBlackTree) SetIfNotExist

1
func (tree *RedBlackTree) SetIfNotExist(key interface{}, value interface{}) bool

SetIfNotExist sets value to the map if the key does not exist, and then returns true. It returns false if key exists, and value would be ignored.

​ 如果 不存在 key ,则 SetIfNotExist 设置为 value 映射,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*RedBlackTree) SetIfNotExistFunc

1
func (tree *RedBlackTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool

SetIfNotExistFunc sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFunc 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

Example

(*RedBlackTree) SetIfNotExistFuncLock

1
func (tree *RedBlackTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function f, and then returns true. It returns false if key exists, and value would be ignored.

​ SetIfNotExistFuncLock 使用回调函数 f 的返回值设置值,然后返回 true。如果 key 存在,则返回 false,并将 value 被忽略。

SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function f with mutex.Lock of the hash map.

​ SetIfNotExistFuncLock 与 SetIfNotExistFunc 函数的不同之处在于它使用互斥锁执行函数 f 。哈希映射的锁定。

Example

(*RedBlackTree) Sets

1
func (tree *RedBlackTree) Sets(data map[interface{}]interface{})

Sets batch sets key-values to the tree.

​ 将批处理设置树的键值。

Example

(*RedBlackTree) Size

1
func (tree *RedBlackTree) Size() int

Size returns number of nodes in the tree.

​ size 返回树中的节点数。

Example

(*RedBlackTree) String

1
func (tree *RedBlackTree) String() string

String returns a string representation of container.

​ String 返回容器的字符串表示形式。

Example

(*RedBlackTree) UnmarshalJSON

1
func (tree *RedBlackTree) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

​ UnmarshalJSON 实现 json 的接口 UnmarshalJSON。元帅。

Example

(*RedBlackTree) UnmarshalValue

1
func (tree *RedBlackTree) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

​ UnmarshalValue 是一个接口实现,用于为 map 设置任何类型的值。

Example

(*RedBlackTree) Values

1
func (tree *RedBlackTree) Values() []interface{}

Values returns all values in asc order based on the key.

​ Values 根据键按 asc 顺序返回所有值。

Example

type RedBlackTreeNode

1
2
3
4
5
type RedBlackTreeNode struct {
	Key   interface{}
	Value interface{}
	// contains filtered or unexported fields
}

RedBlackTreeNode is a single element within the tree.

​ RedBlackTreeNode 是树中的单个元素。

最后修改 October 10, 2024: 更新 (a4b8f85)