skiplist

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SKIPLIST_MAXLEVEL = 32
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found element")
)

Functions

This section is empty.

Types

type Node

type Node[K constraints.Ordered, T any] struct {
	NodeLevel []struct {
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

type Number

type Number[K constraints.Ordered] struct {
	Total    int
	Keys     []K
	Level    []int
	MaxLevel []int
}

debug 使用

type SkipList

type SkipList[K constraints.Ordered, T any] struct {
	// contains filtered or unexported fields
}

func New

func New[K constraints.Ordered, T any]() *SkipList[K, T]

初始化skiplist func New[T any](compare func(T, T) int) *SkipList[T] {

func (*SkipList[K, T]) Delete

func (s *SkipList[K, T]) Delete(score K)

根据score删除

func (*SkipList[K, T]) Draw

func (s *SkipList[K, T]) Draw() *SkipList[K, T]

func (*SkipList[K, T]) Get

func (s *SkipList[K, T]) Get(score K) (elem T)

根据score获取value值

func (*SkipList[K, T]) GetWithBool added in v0.0.6

func (s *SkipList[K, T]) GetWithBool(score K) (elem T, ok bool)

获取

func (*SkipList[K, T]) GetWithMeta

func (s *SkipList[K, T]) GetWithMeta(score K) (elem T, number Number[K], ok bool)

debug使用, 返回查找某个key 比较的次数+经过的节点数

func (*SkipList[K, T]) Insert

func (s *SkipList[K, T]) Insert(score K, elem T)

设置值

func (*SkipList[K, T]) InsertInner

func (s *SkipList[K, T]) InsertInner(score K, elem T, level int) (prev T, replaced bool)

方便给作者调试用的函数

func (*SkipList[K, T]) Len

func (s *SkipList[K, T]) Len() int

返回长度

func (*SkipList[K, T]) Range

func (s *SkipList[K, T]) Range(callback func(score K, v T) bool)

遍历

func (*SkipList[K, T]) RangePrev

func (s *SkipList[K, T]) RangePrev(callback func(k K, v T) bool) *SkipList[K, T]

从后向前倒序遍历b tree

func (*SkipList[K, T]) Remove

func (s *SkipList[K, T]) Remove(score K) *SkipList[K, T]

根据score删除元素

func (*SkipList[K, T]) Set

func (s *SkipList[K, T]) Set(score K, elem T)

设置值, 和Insert是同义词

func (*SkipList[K, T]) SetWithPrev

func (s *SkipList[K, T]) SetWithPrev(score K, elem T) (prev T, replaced bool)

func (*SkipList[K, T]) TopMax

func (s *SkipList[K, T]) TopMax(limit int, callback func(k K, v T) bool)

返回最大的n个值, 降序返回, 10, 9, 8, 7

func (*SkipList[K, T]) TopMin

func (s *SkipList[K, T]) TopMin(limit int, callback func(score K, v T) bool)

返回最小的n个值, 升序返回, 比如0,1,2,3

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL