skiplist

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxLevel    = 16  // 最大层数
	DefaultProbability = 0.5 // 晋升概率 1/2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[T any] struct {
	// contains filtered or unexported fields
}

Node 跳表节点

type SkipList

type SkipList[T any] struct {
	// contains filtered or unexported fields
}

SkipList 泛型跳表

func New

func New[T any](better func(a, b T) bool, withRWLock bool) *SkipList[T]

New 创建新的跳表 better: 比较函数,返回 true 表示 a 排在 b 前面(即 a 更小/优先级更高)

func NewWithConfig

func NewWithConfig[T any](better func(a, b T) bool, maxLevel int, probability float64, withRWLock bool) *SkipList[T]

NewWithConfig 使用自定义配置创建跳表

func (*SkipList[T]) Clear

func (sl *SkipList[T]) Clear()

Clear 清空跳表

func (*SkipList[T]) Contains

func (sl *SkipList[T]) Contains(value T) bool

Contains 检查元素是否存在

func (*SkipList[T]) Delete

func (sl *SkipList[T]) Delete(value T) bool

Delete 删除元素(并发安全)

func (*SkipList[T]) GetAll

func (sl *SkipList[T]) GetAll() []T

GetAll 获取所有元素(按序)

func (*SkipList[T]) GetMax

func (sl *SkipList[T]) GetMax() T

GetMax 获取最大元素(并发安全)

func (*SkipList[T]) GetMin

func (sl *SkipList[T]) GetMin() T

GetMin 获取最小元素(并发安全)

func (*SkipList[T]) Insert

func (sl *SkipList[T]) Insert(value T)

Insert 插入元素(并发安全)

func (*SkipList[T]) Len

func (sl *SkipList[T]) Len() int

Len 获取元素数量(并发安全)

func (*SkipList[T]) RangeQuery

func (sl *SkipList[T]) RangeQuery(min, max T) []T

RangeQuery 范围查询(并发安全) 返回 [min, max] 范围内的所有元素

func (*SkipList[T]) Search

func (sl *SkipList[T]) Search(value T) *Node[T]

Search 查找元素(并发安全)

Jump to

Keyboard shortcuts

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