Documentation
¶
Index ¶
- Constants
- Variables
- type Color
- type Node
- type Option
- type Options
- type RbTree
- func (t *RbTree[K, V]) Begin() *Node[K, V]
- func (t *RbTree[K, V]) Clear()
- func (t *RbTree[K, V]) Contains(key K) bool
- func (t *RbTree[K, V]) Delete(node *Node[K, V])
- func (t *RbTree[K, V]) Empty() bool
- func (t *RbTree[K, V]) Find(key K) (V, error)
- func (t *RbTree[K, V]) FindLowerBoundNode(key K) *Node[K, V]
- func (t *RbTree[K, V]) FindNode(key K) *Node[K, V]
- func (t *RbTree[K, V]) FindUpperBoundNode(key K) *Node[K, V]
- func (t *RbTree[K, V]) First() *Node[K, V]
- func (t *RbTree[K, V]) Get(key K) (V, bool)
- func (t *RbTree[K, V]) GetOrSet(key K, value V) (V, bool)
- func (t *RbTree[K, V]) GetOrSetFunc(key K, fn func() V) (V, bool)
- func (t *RbTree[K, V]) Insert(key K, value V)
- func (t *RbTree[K, V]) IsRbTree() (bool, error)
- func (t *RbTree[K, V]) IterFirst() *RbTreeIterator[K, V]
- func (t *RbTree[K, V]) IterLast() *RbTreeIterator[K, V]
- func (t *RbTree[K, V]) IteratorAsc(visitor visitor.KvVisitor[K, V])
- func (t *RbTree[K, V]) IteratorDesc(visitor visitor.KvVisitor[K, V])
- func (t *RbTree[K, V]) Keys() []K
- func (t *RbTree[K, V]) Last() *Node[K, V]
- func (t *RbTree[K, V]) RBegin() *Node[K, V]
- func (t *RbTree[K, V]) Remove(key K) (V, bool)
- func (t *RbTree[K, V]) Search(key K) (V, bool)
- func (t *RbTree[K, V]) Set(key K, value V) V
- func (t *RbTree[K, V]) SetIfNotExist(key K, value V) bool
- func (t *RbTree[K, V]) Size() int
- func (t *RbTree[K, V]) String() string
- func (t *RbTree[K, V]) Traversal(visitor visitor.KvVisitor[K, V])
- func (t *RbTree[K, V]) Values() []V
- type RbTreeIterator
- func (iter *RbTreeIterator[K, V]) Clone() iterator.ConstIterator[V]
- func (iter *RbTreeIterator[K, V]) Equal(other iterator.ConstIterator[V]) bool
- func (iter *RbTreeIterator[K, V]) IsValid() bool
- func (iter *RbTreeIterator[K, V]) Key() K
- func (iter *RbTreeIterator[K, V]) Next() iterator.ConstIterator[V]
- func (iter *RbTreeIterator[K, V]) Prev() iterator.ConstBidIterator[V]
- func (iter *RbTreeIterator[K, V]) SetValue(val V) error
- func (iter *RbTreeIterator[K, V]) Value() V
- type RbTreeSync
- func (t *RbTreeSync[K, V]) Contains(key K) bool
- func (t *RbTreeSync[K, V]) Diff(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
- func (t *RbTreeSync[K, V]) Empty() bool
- func (t *RbTreeSync[K, V]) Get(key K) (V, bool)
- func (t *RbTreeSync[K, V]) GetOrSet(key K, value V) (V, bool)
- func (t *RbTreeSync[K, V]) GetOrSetFunc(key K, fn func() V) (V, bool)
- func (t *RbTreeSync[K, V]) Insert(key K, value V)
- func (t *RbTreeSync[K, V]) Intersect(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
- func (t *RbTreeSync[K, V]) IsDiff(other *RbTreeSync[K, V]) bool
- func (t *RbTreeSync[K, V]) IsIntersect(other *RbTreeSync[K, V]) bool
- func (t *RbTreeSync[K, V]) IteratorAsc(visitor visitor.KvVisitor[K, V])
- func (t *RbTreeSync[K, V]) IteratorDesc(visitor visitor.KvVisitor[K, V])
- func (t *RbTreeSync[K, V]) Keys() []K
- func (t *RbTreeSync[K, V]) Remove(key K) (V, bool)
- func (t *RbTreeSync[K, V]) Search(key K) (V, bool)
- func (t *RbTreeSync[K, V]) Set(key K, value V) V
- func (t *RbTreeSync[K, V]) SetIfNotExist(key K, value V) bool
- func (t *RbTreeSync[K, V]) Size() int
- func (t *RbTreeSync[K, V]) String() string
- func (t *RbTreeSync[K, V]) UnIntersect(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
- func (t *RbTreeSync[K, V]) Union(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
- func (t *RbTreeSync[K, V]) Values() []V
Constants ¶
const ( RED = false BLACK = true )
Define node 's colors
Variables ¶
var ErrorNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node[K, V any] struct { // contains filtered or unexported fields }
Node is a tree node
type Option ¶ added in v1.3.3
type Option func(option *Options)
Option is a function type used to set Options
func WithGoroutineSafe ¶ added in v1.3.3
func WithGoroutineSafe() Option
WithGoroutineSafe is used to set the set goroutine-safe Note that iterators are not goroutine safe, and it is useless to turn on the setting option here. so don't use iterators in multi goroutines
type Options ¶ added in v1.3.3
type Options struct {
// contains filtered or unexported fields
}
Options holds the Set's options
type RbTree ¶
type RbTree[K, V any] struct { // contains filtered or unexported fields }
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]) Find ¶
Find finds the first node that the key is equal to the passed key, and returns its value
func (*RbTree[K, V]) FindLowerBoundNode ¶
FindLowerBoundNode finds the first node that its key is equal or greater than the passed key, and returns it 返回 >=key 的node
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 从key开始向上找 用正序查找 返回大于或者等于key的第一个值 ,从最小值开始查找. next
func (*RbTree[K, V]) Get ¶ added in v1.3.3
Find finds the first node that the key is equal to the passed key, and returns its value
func (*RbTree[K, V]) GetOrSetFunc ¶ added in v1.3.9
func (*RbTree[K, V]) Insert ¶
func (t *RbTree[K, V]) Insert(key K, value V)
这个地方如果key,已经存在了,还是会添加,会出现多个相同的key 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
func (*RbTree[K, V]) IteratorAsc ¶ added in v1.3.1
IteratorDesc traversals elements in the RbTree, it will not stop until to the end of RbTree or the visitor returns false
func (*RbTree[K, V]) IteratorDesc ¶ added in v1.3.1
IteratorDesc traversals elements in the RbTree, it will not stop until to the end of RbTree or the visitor returns false
func (*RbTree[K, V]) Set ¶ added in v1.3.9
func (t *RbTree[K, V]) Set(key K, value V) V
如果存在,则进行替换。返回旧值
func (*RbTree[K, V]) SetIfNotExist ¶ added in v1.3.14
type RbTreeIterator ¶
type RbTreeIterator[K, V any] struct { // contains filtered or unexported fields }
RbTreeIterator is an iterator implementation of RbTree
func NewIterator ¶
func NewIterator[K, V any](node *Node[K, V]) *RbTreeIterator[K, V]
NewIterator creates a RbTreeIterator from the passed node
func (*RbTreeIterator[K, V]) Clone ¶
func (iter *RbTreeIterator[K, V]) Clone() iterator.ConstIterator[V]
Clone clones the iterator into a new RbTreeIterator
func (*RbTreeIterator[K, V]) Equal ¶
func (iter *RbTreeIterator[K, V]) Equal(other iterator.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() iterator.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() iterator.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
type RbTreeSync ¶ added in v1.3.3
type RbTreeSync[K, V any] struct { Tree *RbTree[K, V] Lock sync.Locker // contains filtered or unexported fields }
func NewSync ¶ added in v1.3.3
func NewSync[K, V any](cmp comparator.Comparator[K], opts ...Option) *RbTreeSync[K, V]
New creates a new NewSync
func (*RbTreeSync[K, V]) Contains ¶ added in v1.3.13
func (t *RbTreeSync[K, V]) Contains(key K) bool
func (*RbTreeSync[K, V]) Diff ¶ added in v1.3.21
func (t *RbTreeSync[K, V]) Diff(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
Diff returns a new set with the elements in the set s but not in the passed set Please ensure s set and other set uses the same keyCmp 返回 other 中没有的部分
func (*RbTreeSync[K, V]) Empty ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Empty() bool
Empty returns true if Tree is empty,otherwise returns false.
func (*RbTreeSync[K, V]) Get ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Get(key K) (V, bool)
Find finds the first node that the key is equal to the passed key, and returns its value
func (*RbTreeSync[K, V]) GetOrSet ¶ added in v1.3.9
func (t *RbTreeSync[K, V]) GetOrSet(key K, value V) (V, bool)
获取,如果没有则设置, 是否找到
func (*RbTreeSync[K, V]) GetOrSetFunc ¶ added in v1.3.9
func (t *RbTreeSync[K, V]) GetOrSetFunc(key K, fn func() V) (V, bool)
func (*RbTreeSync[K, V]) Insert ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Insert(key K, value V)
这个地方如果key,已经存在了,还是会添加,会出现多个相同的key
func (*RbTreeSync[K, V]) Intersect ¶ added in v1.3.21
func (t *RbTreeSync[K, V]) Intersect(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
Intersect returns a new set with the common elements in the set s and the passed set Please ensure s set and other set uses the same keyCmp
func (*RbTreeSync[K, V]) IsDiff ¶ added in v1.3.21
func (t *RbTreeSync[K, V]) IsDiff(other *RbTreeSync[K, V]) bool
如果不同返回true,相同返回false
func (*RbTreeSync[K, V]) IsIntersect ¶ added in v1.3.23
func (t *RbTreeSync[K, V]) IsIntersect(other *RbTreeSync[K, V]) bool
如果交叉返回true ,否则 false
func (*RbTreeSync[K, V]) IteratorAsc ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) IteratorAsc(visitor visitor.KvVisitor[K, V])
IteratorDesc traversals elements in the RbTree, it will not stop until to the end of RbTree or the visitor returns false
func (*RbTreeSync[K, V]) IteratorDesc ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) IteratorDesc(visitor visitor.KvVisitor[K, V])
IteratorDesc traversals elements in the RbTree, it will not stop until to the end of RbTree or the visitor returns false
func (*RbTreeSync[K, V]) Keys ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Keys() []K
func (*RbTreeSync[K, V]) Remove ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Remove(key K) (V, bool)
func (*RbTreeSync[K, V]) Search ¶ added in v1.3.9
func (t *RbTreeSync[K, V]) Search(key K) (V, bool)
func (*RbTreeSync[K, V]) Set ¶ added in v1.3.9
func (t *RbTreeSync[K, V]) Set(key K, value V) V
如果存在,则进行替换。返回旧值
func (*RbTreeSync[K, V]) SetIfNotExist ¶ added in v1.3.14
func (t *RbTreeSync[K, V]) SetIfNotExist(key K, value V) bool
func (*RbTreeSync[K, V]) Size ¶ added in v1.3.3
func (t *RbTreeSync[K, V]) Size() int
Size returns the size of the rbtree.
func (*RbTreeSync[K, V]) String ¶ added in v1.3.17
func (t *RbTreeSync[K, V]) String() string
func (*RbTreeSync[K, V]) UnIntersect ¶ added in v1.3.21
func (t *RbTreeSync[K, V]) UnIntersect(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
Union returns a new set with the all elements in the set s and the passed set Please ensure s set and other set uses the same keyCmp 和 Intersect 相反 ,返回两个不同部分
func (*RbTreeSync[K, V]) Union ¶ added in v1.3.21
func (t *RbTreeSync[K, V]) Union(other *RbTreeSync[K, V]) *RbTreeSync[K, V]
Union returns a new set with the all elements in the set s and the passed set Please ensure s set and other set uses the same keyCmp
func (*RbTreeSync[K, V]) Values ¶ added in v1.3.13
func (t *RbTreeSync[K, V]) Values() []V