Documentation ¶
Overview ¶
Package gtree provides concurrent-safe/unsafe tree containers.
Index ¶
- type AVLTree
- func (tree *AVLTree) Ceiling(key interface{}) (floor *AVLTreeNode, found bool)
- func (tree *AVLTree) Clear()
- func (tree *AVLTree) Clone(unsafe ...bool) *AVLTree
- func (tree *AVLTree) Contains(key interface{}) bool
- func (tree *AVLTree) Flip(comparator ...func(v1, v2 interface{}) int)
- func (tree *AVLTree) Floor(key interface{}) (floor *AVLTreeNode, found bool)
- func (tree *AVLTree) Get(key interface{}) (value interface{})
- func (tree *AVLTree) GetOrSet(key interface{}, value interface{}) interface{}
- func (tree *AVLTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
- func (tree *AVLTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
- func (tree *AVLTree) GetVar(key interface{}) *gvar.Var
- func (tree *AVLTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var
- func (tree *AVLTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var
- func (tree *AVLTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var
- func (tree *AVLTree) IsEmpty() bool
- func (tree *AVLTree) Iterator(f func(key, value interface{}) bool)
- func (tree *AVLTree) IteratorAsc(f func(key, value interface{}) bool)
- func (tree *AVLTree) IteratorDesc(f func(key, value interface{}) bool)
- func (tree *AVLTree) Keys() []interface{}
- func (tree *AVLTree) Left() *AVLTreeNode
- func (tree *AVLTree) Map() map[interface{}]interface{}
- func (tree *AVLTree) Print()
- func (tree *AVLTree) Remove(key interface{}) (value interface{})
- func (tree *AVLTree) Removes(keys []interface{})
- func (tree *AVLTree) Right() *AVLTreeNode
- func (tree *AVLTree) Search(key interface{}) (value interface{}, found bool)
- func (tree *AVLTree) Set(key interface{}, value interface{})
- func (tree *AVLTree) SetIfNotExist(key interface{}, value interface{}) bool
- func (tree *AVLTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool
- func (tree *AVLTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool
- func (tree *AVLTree) Sets(data map[interface{}]interface{})
- func (tree *AVLTree) Size() int
- func (tree *AVLTree) String() string
- func (tree *AVLTree) Values() []interface{}
- type AVLTreeNode
- type BTree
- func (tree *BTree) Clear()
- func (tree *BTree) Clone(unsafe ...bool) *BTree
- func (tree *BTree) Contains(key interface{}) bool
- func (tree *BTree) Get(key interface{}) (value interface{})
- func (tree *BTree) GetOrSet(key interface{}, value interface{}) interface{}
- func (tree *BTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
- func (tree *BTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
- func (tree *BTree) GetVar(key interface{}) *gvar.Var
- func (tree *BTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var
- func (tree *BTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var
- func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var
- func (tree *BTree) Height() int
- func (tree *BTree) IsEmpty() bool
- func (tree *BTree) Iterator(f func(key, value interface{}) bool)
- func (tree *BTree) IteratorAsc(f func(key, value interface{}) bool)
- func (tree *BTree) IteratorDesc(f func(key, value interface{}) bool)
- func (tree *BTree) Keys() []interface{}
- func (tree *BTree) Left() *BTreeEntry
- func (tree *BTree) Map() map[interface{}]interface{}
- func (tree *BTree) Print()
- func (tree *BTree) Remove(key interface{}) (value interface{})
- func (tree *BTree) Removes(keys []interface{})
- func (tree *BTree) Right() *BTreeEntry
- func (tree *BTree) Search(key interface{}) (value interface{}, found bool)
- func (tree *BTree) Set(key interface{}, value interface{})
- func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool
- func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool
- func (tree *BTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool
- func (tree *BTree) Sets(data map[interface{}]interface{})
- func (tree *BTree) Size() int
- func (tree *BTree) String() string
- func (tree *BTree) Values() []interface{}
- type BTreeEntry
- type BTreeNode
- type RedBlackTree
- func (tree *RedBlackTree) Ceiling(key interface{}) (ceiling *RedBlackTreeNode)
- func (tree *RedBlackTree) Clear()
- func (tree *RedBlackTree) Clone(unsafe ...bool) *RedBlackTree
- func (tree *RedBlackTree) Contains(key interface{}) bool
- func (tree *RedBlackTree) Flip(comparator ...func(v1, v2 interface{}) int)
- func (tree *RedBlackTree) Floor(key interface{}) (floor *RedBlackTreeNode)
- func (tree *RedBlackTree) Get(key interface{}) (value interface{})
- func (tree *RedBlackTree) GetOrSet(key interface{}, value interface{}) interface{}
- func (tree *RedBlackTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
- func (tree *RedBlackTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
- func (tree *RedBlackTree) GetVar(key interface{}) *gvar.Var
- func (tree *RedBlackTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var
- func (tree *RedBlackTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var
- func (tree *RedBlackTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var
- func (tree *RedBlackTree) IsEmpty() bool
- func (tree *RedBlackTree) Iterator(f func(key, value interface{}) bool)
- func (tree *RedBlackTree) IteratorAsc(f func(key, value interface{}) bool)
- func (tree *RedBlackTree) IteratorDesc(f func(key, value interface{}) bool)
- func (tree *RedBlackTree) Keys() []interface{}
- func (tree *RedBlackTree) Left() *RedBlackTreeNode
- func (tree *RedBlackTree) Map() map[interface{}]interface{}
- func (tree *RedBlackTree) Print()
- func (tree *RedBlackTree) Remove(key interface{}) (value interface{})
- func (tree *RedBlackTree) Removes(keys []interface{})
- func (tree *RedBlackTree) Right() *RedBlackTreeNode
- func (tree *RedBlackTree) Search(key interface{}) (value interface{}, found bool)
- func (tree *RedBlackTree) Set(key interface{}, value interface{})
- func (tree *RedBlackTree) SetIfNotExist(key interface{}, value interface{}) bool
- func (tree *RedBlackTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool
- func (tree *RedBlackTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool
- func (tree *RedBlackTree) Sets(data map[interface{}]interface{})
- func (tree *RedBlackTree) Size() int
- func (tree *RedBlackTree) String() string
- func (tree *RedBlackTree) Values() []interface{}
- type RedBlackTreeNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AVLTree ¶
type AVLTree struct {
// contains filtered or unexported fields
}
AVLTree holds elements of the AVL tree.
func NewAVLTree ¶
NewAVLTree instantiates an AVL tree with the custom comparator. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.
func NewAVLTreeFrom ¶
func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *AVLTree
NewAVLTreeFrom instantiates an AVL tree with the custom comparator and data map. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.
func (*AVLTree) Ceiling ¶
func (tree *AVLTree) Ceiling(key interface{}) (floor *AVLTreeNode, found bool)
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 is smaller than the given node.
Key should adhere to the comparator's type assertion, otherwise method panics.
func (*AVLTree) Flip ¶
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.
If the type of value is different with key, you pass the new <comparator>.
func (*AVLTree) Floor ¶
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 ceiling 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 is larger than the given node.
Key should adhere to the comparator's type assertion, otherwise method panics.
func (*AVLTree) Get ¶
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.
func (*AVLTree) GetOrSet ¶
func (tree *AVLTree) GetOrSet(key interface{}, value interface{}) interface{}
GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.
func (*AVLTree) GetOrSetFunc ¶
func (tree *AVLTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
func (*AVLTree) GetOrSetFuncLock ¶
func (tree *AVLTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*AVLTree) GetVar ¶
GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.
func (*AVLTree) GetVarOrSet ¶
GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.
func (*AVLTree) GetVarOrSetFunc ¶
GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.
func (*AVLTree) GetVarOrSetFuncLock ¶
GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.
func (*AVLTree) IteratorAsc ¶
IteratorAsc iterates the tree in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*AVLTree) IteratorDesc ¶
IteratorDesc iterates the tree in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*AVLTree) Keys ¶
func (tree *AVLTree) Keys() []interface{}
Keys returns all keys in asc order.
func (*AVLTree) Left ¶
func (tree *AVLTree) Left() *AVLTreeNode
Left returns the minimum element of the AVL tree or nil if the tree is empty.
func (*AVLTree) Map ¶
func (tree *AVLTree) Map() map[interface{}]interface{}
Map returns all key-value items as map.
func (*AVLTree) Remove ¶
func (tree *AVLTree) Remove(key interface{}) (value interface{})
Remove remove the node from the tree by key. Key should adhere to the comparator's type assertion, otherwise method panics.
func (*AVLTree) Removes ¶
func (tree *AVLTree) Removes(keys []interface{})
Removes batch deletes values of the tree by <keys>.
func (*AVLTree) Right ¶
func (tree *AVLTree) Right() *AVLTreeNode
Right returns the maximum element of the AVL tree or nil if the tree is empty.
func (*AVLTree) Search ¶
Search searches the tree with given <key>. Second return parameter <found> is true if key was found, otherwise false.
func (*AVLTree) Set ¶
func (tree *AVLTree) Set(key interface{}, value interface{})
Set inserts node into the tree.
func (*AVLTree) SetIfNotExist ¶
SetIfNotExist sets <value> to the map if the <key> does not exist, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*AVLTree) SetIfNotExistFunc ¶
SetIfNotExistFunc sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*AVLTree) SetIfNotExistFuncLock ¶
SetIfNotExistFuncLock sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*AVLTree) Sets ¶
func (tree *AVLTree) Sets(data map[interface{}]interface{})
Sets batch sets key-values to the tree.
type AVLTreeNode ¶
type AVLTreeNode struct { Key interface{} Value interface{} // contains filtered or unexported fields }
AVLTreeNode is a single element within the tree.
func (*AVLTreeNode) Next ¶
func (node *AVLTreeNode) Next() *AVLTreeNode
Next returns the next element in an inorder walk of the AVL tree.
func (*AVLTreeNode) Prev ¶
func (node *AVLTreeNode) Prev() *AVLTreeNode
Prev returns the previous element in an inorder walk of the AVL tree.
type BTree ¶
type BTree struct {
// contains filtered or unexported fields
}
BTree holds elements of the B-tree.
func NewBTree ¶
NewBTree instantiates a B-tree with <m> (maximum number of children) and a custom key comparator. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default. Note that the <m> must be greater or equal than 3, or else it panics.
func NewBTreeFrom ¶
func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *BTree
NewBTreeFrom instantiates a B-tree with <m> (maximum number of children), a custom key comparator and data map. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.
func (*BTree) Get ¶
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.
func (*BTree) GetOrSet ¶
func (tree *BTree) GetOrSet(key interface{}, value interface{}) interface{}
GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.
func (*BTree) GetOrSetFunc ¶
func (tree *BTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
func (*BTree) GetOrSetFuncLock ¶
func (tree *BTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*BTree) GetVar ¶
GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.
func (*BTree) GetVarOrSet ¶
GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.
func (*BTree) GetVarOrSetFunc ¶
GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.
func (*BTree) GetVarOrSetFuncLock ¶
GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.
func (*BTree) IteratorAsc ¶
IteratorAsc iterates the tree in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*BTree) IteratorDesc ¶
IteratorDesc iterates the tree in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*BTree) Left ¶
func (tree *BTree) Left() *BTreeEntry
Left returns the left-most (min) entry or nil if tree is empty.
func (*BTree) Map ¶
func (tree *BTree) Map() map[interface{}]interface{}
Map returns all key-value items as map.
func (*BTree) Remove ¶
func (tree *BTree) Remove(key interface{}) (value interface{})
Remove removes the node from the tree by <key>.
func (*BTree) Removes ¶
func (tree *BTree) Removes(keys []interface{})
Removes batch deletes values of the tree by <keys>.
func (*BTree) Right ¶
func (tree *BTree) Right() *BTreeEntry
Right returns the right-most (max) entry or nil if tree is empty.
func (*BTree) Search ¶
Search searches the tree with given <key>. Second return parameter <found> is true if key was found, otherwise false.
func (*BTree) Set ¶
func (tree *BTree) Set(key interface{}, value interface{})
Set inserts key-value item into the tree.
func (*BTree) SetIfNotExist ¶
SetIfNotExist sets <value> to the map if the <key> does not exist, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*BTree) SetIfNotExistFunc ¶
SetIfNotExistFunc sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*BTree) SetIfNotExistFuncLock ¶
SetIfNotExistFuncLock sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*BTree) Sets ¶
func (tree *BTree) Sets(data map[interface{}]interface{})
Sets batch sets key-values to the tree.
type BTreeEntry ¶
type BTreeEntry struct { Key interface{} Value interface{} }
BTreeEntry represents the key-value pair contained within nodes.
type BTreeNode ¶
type BTreeNode struct { Parent *BTreeNode Entries []*BTreeEntry // Contained keys in node Children []*BTreeNode // Children nodes }
BTreeNode is a single element within the tree.
type RedBlackTree ¶
type RedBlackTree struct {
// contains filtered or unexported fields
}
RedBlackTree holds elements of the red-black tree.
func NewRedBlackTree ¶
func NewRedBlackTree(comparator func(v1, v2 interface{}) int, unsafe ...bool) *RedBlackTree
NewRedBlackTree instantiates a red-black tree with the custom comparator. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.
func NewRedBlackTreeFrom ¶
func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *RedBlackTree
NewRedBlackTreeFrom instantiates a red-black tree with the custom comparator and <data> map. The param <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.
func (*RedBlackTree) Ceiling ¶
func (tree *RedBlackTree) Ceiling(key interface{}) (ceiling *RedBlackTreeNode)
Ceiling finds ceiling node of the input <key>, return the ceiling node or nil if no ceiling is found.
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.
func (*RedBlackTree) Clear ¶
func (tree *RedBlackTree) Clear()
Clear removes all nodes from the tree.
func (*RedBlackTree) Clone ¶
func (tree *RedBlackTree) Clone(unsafe ...bool) *RedBlackTree
Clone returns a new tree with a copy of current tree.
func (*RedBlackTree) Contains ¶
func (tree *RedBlackTree) Contains(key interface{}) bool
Contains checks whether <key> exists in the tree.
func (*RedBlackTree) Flip ¶
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.
If the type of value is different with key, you pass the new <comparator>.
func (*RedBlackTree) Floor ¶
func (tree *RedBlackTree) Floor(key interface{}) (floor *RedBlackTreeNode)
Floor Finds floor node of the input <key>, return the floor node or nil if no floor is found.
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.
func (*RedBlackTree) Get ¶
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.
func (*RedBlackTree) GetOrSet ¶
func (tree *RedBlackTree) GetOrSet(key interface{}, value interface{}) interface{}
GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.
func (*RedBlackTree) GetOrSetFunc ¶
func (tree *RedBlackTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{}
GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
func (*RedBlackTree) GetOrSetFuncLock ¶
func (tree *RedBlackTree) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.
GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*RedBlackTree) GetVar ¶
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.
func (*RedBlackTree) GetVarOrSet ¶
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.
func (*RedBlackTree) GetVarOrSetFunc ¶
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.
func (*RedBlackTree) GetVarOrSetFuncLock ¶
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.
func (*RedBlackTree) IsEmpty ¶
func (tree *RedBlackTree) IsEmpty() bool
IsEmpty returns true if tree does not contain any nodes.
func (*RedBlackTree) Iterator ¶
func (tree *RedBlackTree) Iterator(f func(key, value interface{}) bool)
Iterator is alias of IteratorAsc.
func (*RedBlackTree) IteratorAsc ¶
func (tree *RedBlackTree) IteratorAsc(f func(key, value interface{}) bool)
IteratorAsc iterates the tree in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*RedBlackTree) IteratorDesc ¶
func (tree *RedBlackTree) IteratorDesc(f func(key, value interface{}) bool)
IteratorDesc iterates the tree in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*RedBlackTree) Keys ¶
func (tree *RedBlackTree) Keys() []interface{}
Keys returns all keys in asc order.
func (*RedBlackTree) Left ¶
func (tree *RedBlackTree) Left() *RedBlackTreeNode
Left returns the left-most (min) node or nil if tree is empty.
func (*RedBlackTree) Map ¶
func (tree *RedBlackTree) Map() map[interface{}]interface{}
Map returns all key-value items as map.
func (*RedBlackTree) Remove ¶
func (tree *RedBlackTree) Remove(key interface{}) (value interface{})
Remove removes the node from the tree by <key>.
func (*RedBlackTree) Removes ¶
func (tree *RedBlackTree) Removes(keys []interface{})
Removes batch deletes values of the tree by <keys>.
func (*RedBlackTree) Right ¶
func (tree *RedBlackTree) Right() *RedBlackTreeNode
Right returns the right-most (max) node or nil if tree is empty.
func (*RedBlackTree) Search ¶
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.
func (*RedBlackTree) Set ¶
func (tree *RedBlackTree) Set(key interface{}, value interface{})
Set inserts key-value item into the tree.
func (*RedBlackTree) SetIfNotExist ¶
func (tree *RedBlackTree) SetIfNotExist(key interface{}, value interface{}) bool
SetIfNotExist sets <value> to the map if the <key> does not exist, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*RedBlackTree) SetIfNotExistFunc ¶
func (tree *RedBlackTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool
SetIfNotExistFunc sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
func (*RedBlackTree) SetIfNotExistFuncLock ¶
func (tree *RedBlackTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool
SetIfNotExistFuncLock sets value with return value of callback function <f>, then return true. It returns false if <key> exists, and <value> would be ignored.
SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function <f> with mutex.Lock of the hash map.
func (*RedBlackTree) Sets ¶
func (tree *RedBlackTree) Sets(data map[interface{}]interface{})
Sets batch sets key-values to the tree.
func (*RedBlackTree) Size ¶
func (tree *RedBlackTree) Size() int
Size returns number of nodes in the tree.
func (*RedBlackTree) String ¶
func (tree *RedBlackTree) String() string
String returns a string representation of container.
func (*RedBlackTree) Values ¶
func (tree *RedBlackTree) Values() []interface{}
Values returns all values in asc order based on the key.
type RedBlackTreeNode ¶
type RedBlackTreeNode struct { Key interface{} Value interface{} // contains filtered or unexported fields }
RedBlackTreeNode is a single element within the tree.