skiplist

package
v6.4.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Big   = -1
	Small = 1
	Equal = 0
)

Compare Const

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator 跳跃表迭代器

func (*Iterator) First

func (sli *Iterator) First() *SkipValue

First 获取第一个节点Value值

func (*Iterator) Last

func (sli *Iterator) Last() *SkipValue

Last 获取最后一个节点Value值

func (*Iterator) Next

func (sli *Iterator) Next() *Iterator

Next 获取迭代器的下一个节点

func (*Iterator) Prev

func (sli *Iterator) Prev() *Iterator

Prev 获取迭代器的上一个节点

func (*Iterator) Seek

func (sli *Iterator) Seek(value *SkipValue) *SkipValue

Seek 迭代器在跳跃表中查找某个位置在传参后面或者与传参相等的SkipValue

func (*Iterator) Value

func (sli *Iterator) Value() *SkipValue

Value 获取迭代器当前的Value

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue skiplist 实现的一个 按照score 排序的队列,score相同的按照元素到的先后排序

func NewQueue

func NewQueue(maxsize int64) *Queue

NewQueue 创建队列

func (*Queue) CreateSkipValue

func (cache *Queue) CreateSkipValue(item Scorer) *SkipValue

CreateSkipValue 创建一个 仅仅有 score 的Value

func (*Queue) Exist

func (cache *Queue) Exist(hash string) bool

Exist 是否存在

func (*Queue) First

func (cache *Queue) First() Scorer

First 取出第一个交易

func (*Queue) GetCacheBytes

func (cache *Queue) GetCacheBytes() int64

GetCacheBytes get cache byte size

func (*Queue) GetItem

func (cache *Queue) GetItem(hash string) (Scorer, error)

GetItem 获取数据通过 key

func (*Queue) Insert

func (cache *Queue) Insert(hash string, item Scorer)

Insert Scorer item to queue

func (*Queue) Last

func (cache *Queue) Last() Scorer

Last 取出最后一个交易

func (*Queue) MaxSize

func (cache *Queue) MaxSize() int64

MaxSize 最大的cache数量

func (*Queue) Push

func (cache *Queue) Push(item Scorer) error

Push item 到队列中,如果插入的数据优先级比队列中更大,那么弹出优先级最小的,然后插入这个数据,否则报错

func (*Queue) Remove

func (cache *Queue) Remove(hash string) error

Remove 删除数据

func (*Queue) Size

func (cache *Queue) Size() int

Size 数据总数

func (*Queue) Walk

func (cache *Queue) Walk(count int, cb func(value Scorer) bool)

Walk 遍历整个队列

type Scorer

type Scorer interface {
	GetScore() int64
	Hash() []byte
	//在score相同情况下的比较
	Compare(Scorer) int
	//占用字节大小
	ByteSize() int64
}

Scorer 接口实现 Value的 Score 功能

type SkipList

type SkipList struct {
	// contains filtered or unexported fields
}

SkipList 跳跃表

func NewSkipList

func NewSkipList(min *SkipValue) *SkipList

NewSkipList 构建一个跳跃表

func (*SkipList) Delete

func (sl *SkipList) Delete(value *SkipValue) int

Delete 删除节点

func (*SkipList) Find

func (sl *SkipList) Find(value *SkipValue) *SkipValue

Find 查找某个跳跃表中的SkipValue

func (*SkipList) FindCount

func (sl *SkipList) FindCount() int

FindCount 返回查询次数

func (*SkipList) FindGreaterOrEqual

func (sl *SkipList) FindGreaterOrEqual(value *SkipValue) *SkipValue

FindGreaterOrEqual 在跳跃表中查找某个位置在传参后面或者与传参相等的SkipValue

func (*SkipList) GetIterator

func (sl *SkipList) GetIterator() *Iterator

GetIterator 获取迭代器

func (*SkipList) Insert

func (sl *SkipList) Insert(value *SkipValue) int

Insert 插入节点

func (*SkipList) Len

func (sl *SkipList) Len() int

Len 返回节点数

func (*SkipList) Level

func (sl *SkipList) Level() int

Level 返回跳跃表的层级

func (*SkipList) Print

func (sl *SkipList) Print()

Print 测试用的输出函数

func (*SkipList) Walk

func (sl *SkipList) Walk(cb func(value interface{}) bool)

Walk 遍历整个结构中SkipValue的Value,如果cb 返回false 那么停止遍历

func (*SkipList) WalkS

func (sl *SkipList) WalkS(cb func(value interface{}) bool)

WalkS 遍历整个结构中的SkipValue,如果cb 返回false 那么停止遍历

type SkipValue

type SkipValue struct {
	Score int64
	Value interface{}
}

SkipValue 跳跃表节点的Value值

func (*SkipValue) Compare

func (v *SkipValue) Compare(value *SkipValue) int

Compare 比较函数,这样的比较排序是从大到小

Jump to

Keyboard shortcuts

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