/
x_skl_intf.go
40 lines (34 loc) · 1.1 KB
/
x_skl_intf.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
package list
import (
"github.com/benz9527/xboot/lib/infra"
)
// The classic and unique skip list.
type SkipList[K infra.OrderedKey, V any] interface {
Levels() int32
Len() int64
IndexCount() uint64
Insert(key K, val V, ifNotPresent ...bool) error
LoadFirst(key K) (SklElement[K, V], error)
RemoveFirst(key K) (SklElement[K, V], error)
Foreach(action func(i int64, item SklIterationItem[K, V]) bool)
PopHead() (SklElement[K, V], error)
PeekHead() SklElement[K, V]
}
// The X means the extended interface and it could store duplicate keys and values.
type XSkipList[K infra.OrderedKey, V any] interface {
SkipList[K, V]
LoadIfMatch(key K, matcher func(that V) bool) ([]SklElement[K, V], error)
LoadAll(key K) ([]SklElement[K, V], error)
RemoveIfMatch(key K, matcher func(that V) bool) ([]SklElement[K, V], error)
RemoveAll(key K) ([]SklElement[K, V], error)
}
type SklElement[K infra.OrderedKey, V any] interface {
Key() K
Val() V
}
type SklIterationItem[K infra.OrderedKey, V any] interface {
SklElement[K, V]
NodeLevel() uint32
NodeItemCount() int64
}
type SklValComparator[V any] func(i, j V) int64