Documentation ¶
Overview ¶
Package gomapllrb implements an in-memory key/value store using LLRB algorithm. LLRB (Left-Leaning Red-Black) is a self-balancing binary search tree that stores the keys in order which allows ordered iteration and find nearest keys.
Copyright (c) 2023, Seungyoung Kim https://github.com/wolkykim/GoMapLLRB
Index ¶
- Constants
- func IsLess[K constraints.Ordered](a, b K) bool
- type Comparator
- type Iter
- type Node
- type PerfStats
- type Stats
- type Tree
- func (tree *Tree[K]) Bigger(name K) (K, interface{}, bool)
- func (tree *Tree[K]) Check() error
- func (tree *Tree[K]) Clear()
- func (tree *Tree[K]) Delete(name K) bool
- func (tree *Tree[K]) EqualOrBigger(name K) (K, interface{}, bool)
- func (tree *Tree[K]) EqualOrSmaller(name K) (K, interface{}, bool)
- func (tree *Tree[K]) Exist(name K) bool
- func (tree *Tree[K]) Get(name K) interface{}
- func (tree *Tree[K]) Iter() *Iter[K]
- func (tree *Tree[K]) Len() int
- func (tree *Tree[K]) Map() map[K]interface{}
- func (tree *Tree[K]) Max() (K, interface{}, bool)
- func (tree *Tree[K]) Min() (K, interface{}, bool)
- func (tree *Tree[K]) Put(name K, data interface{})
- func (tree *Tree[K]) Range(start, end K) *Iter[K]
- func (tree *Tree[K]) ResetStats()
- func (tree *Tree[K]) SetLess(fn Comparator[K])
- func (tree *Tree[K]) Smaller(name K) (K, interface{}, bool)
- func (tree *Tree[K]) Stats() Stats
- func (tree *Tree[K]) String() string
Constants ¶
const ( // LLRB234 sets the tree management property and algorithm. LLRB234 = true // true: 2-3-4 varian(default), false: 2-3 variant )
Variables ¶
This section is empty.
Functions ¶
func IsLess ¶ added in v1.0.1
func IsLess[K constraints.Ordered](a, b K) bool
IsLess is the default comparator.
Types ¶
type Iter ¶ added in v1.0.1
type Iter[K constraints.Ordered] struct { // contains filtered or unexported fields }
Iter is a iterator object.
type Node ¶
type Node[K constraints.Ordered] struct { // contains filtered or unexported fields }
Node is like an apple on the apple trees.
type Stats ¶
type Stats struct { Put struct { Sum uint64 New uint64 Update uint64 } Delete struct { Sum uint64 Deleted uint64 NotFound uint64 } Get struct { Sum uint64 Found uint64 NotFound uint64 } Perf PerfStats }
Stats provides usage statistics accessible via Stats() method.
type Tree ¶
type Tree[K constraints.Ordered] struct { // contains filtered or unexported fields }
Tree is the glorious tree struct.
func (*Tree[K]) Check ¶
Check checks that the invariants of the red-black tree are satisfied.
Root property: The root is black. Red property: If a node is red, then both its children are black. Black property: For each node, all simple paths from the node to descendant leaves contain the same number of black nodes. LLRB property: 3-nodes always lean to the left and 4-nodes are balanced.
func (*Tree[K]) Clear ¶
func (tree *Tree[K]) Clear()
Clear empties the tree without resetting the statistic metrics.
func (*Tree[K]) EqualOrBigger ¶
EqualOrBigger finds a matching key or the next bigger key.
func (*Tree[K]) EqualOrSmaller ¶
EqualOrSmaller finds a matching key or the next smaller key.
func (*Tree[K]) Get ¶
func (tree *Tree[K]) Get(name K) interface{}
Get returns the value of the key. If key is not found, it returns Nil. When Nil value is expected as a actual value, use Exist() instead.
func (*Tree[K]) Map ¶ added in v1.0.6
func (tree *Tree[K]) Map() map[K]interface{}
Map returns the tree in a map
func (*Tree[K]) Put ¶
func (tree *Tree[K]) Put(name K, data interface{})
Put inserts a new key or replaces old if the same key is found.
func (*Tree[K]) ResetStats ¶
func (tree *Tree[K]) ResetStats()
ResetStats resets all the satistics metrics.
func (*Tree[K]) SetLess ¶
func (tree *Tree[K]) SetLess(fn Comparator[K])
SetLess sets a user comparator function.
func myLess[K constraints.Ordered](a, b K) bool { // return true if a < b, or false }