github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/list/x_com_skl_node.go (about)

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