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

     1  package list
     2  
     3  import (
     4  	"github.com/benz9527/xboot/lib/infra"
     5  )
     6  
     7  // The classic and unique skip list.
     8  type SkipList[K infra.OrderedKey, V any] interface {
     9  	Levels() int32
    10  	Len() int64
    11  	IndexCount() uint64
    12  	Insert(key K, val V, ifNotPresent ...bool) error
    13  	LoadFirst(key K) (SklElement[K, V], error)
    14  	RemoveFirst(key K) (SklElement[K, V], error)
    15  	Foreach(action func(i int64, item SklIterationItem[K, V]) bool)
    16  	PopHead() (SklElement[K, V], error)
    17  	PeekHead() SklElement[K, V]
    18  }
    19  
    20  // The X means the extended interface and it could store duplicate keys and values.
    21  type XSkipList[K infra.OrderedKey, V any] interface {
    22  	SkipList[K, V]
    23  	LoadIfMatch(key K, matcher func(that V) bool) ([]SklElement[K, V], error)
    24  	LoadAll(key K) ([]SklElement[K, V], error)
    25  	RemoveIfMatch(key K, matcher func(that V) bool) ([]SklElement[K, V], error)
    26  	RemoveAll(key K) ([]SklElement[K, V], error)
    27  }
    28  
    29  type SklElement[K infra.OrderedKey, V any] interface {
    30  	Key() K
    31  	Val() V
    32  }
    33  
    34  type SklIterationItem[K infra.OrderedKey, V any] interface {
    35  	SklElement[K, V]
    36  	NodeLevel() uint32
    37  	NodeItemCount() int64
    38  }
    39  
    40  type SklValComparator[V any] func(i, j V) int64