/
x_com_skl_node.go
48 lines (40 loc) · 1.28 KB
/
x_com_skl_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package list
import (
"github.com/benz9527/xboot/lib/infra"
)
// The cache level array index > 0, it is the Y axis, and it means that it is the interval after
// the bisection search. Used to locate an element quickly.
// The cache level array index == 0, it is the X axis, and it means that it is the bits container.
type xComSklNode[K infra.OrderedKey, V any] struct {
// The cache part.
// When the current node works as a data node, it doesn't contain levels metadata.
// If a node is a level node, the cache is from levels[0], but it is differed
// to the sentinel's levels[0].
indices []*xComSklNode[K, V] // The cache level array.
element SklElement[K, V]
// Works for a backward iteration direction.
pred *xComSklNode[K, V]
}
func (node *xComSklNode[K, V]) Element() SklElement[K, V] {
return node.element
}
func (node *xComSklNode[K, V]) setElement(e SklElement[K, V]) {
node.element = e
}
func (node *xComSklNode[K, V]) backward() *xComSklNode[K, V] {
return node.pred
}
func (node *xComSklNode[K, V]) setBackward(pred *xComSklNode[K, V]) {
node.pred = pred
}
func (node *xComSklNode[K, V]) levels() []*xComSklNode[K, V] {
if node == nil {
return nil
}
return node.indices
}
func (node *xComSklNode[K, V]) Free() {
node.element = nil
node.pred = nil
node.indices = nil
}