Skip to content

Latest commit

 

History

History
188 lines (102 loc) · 4.43 KB

skiplist.md

File metadata and controls

188 lines (102 loc) · 4.43 KB

skiplist

import "github.com/andy2046/gopie/pkg/skiplist"

Package skiplist provides a Skip List implementation.

skiplist.go types.go

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

Element represents an element in the list.

func (*Element) Key

func (e *Element) Key() string

Key returns the given Element key.

func (*Element) Next

func (e *Element) Next() *Element

Next returns the adjacent next Element if existed or nil otherwise.

func (*Element) NextLevel

func (e *Element) NextLevel(level int) *Element

NextLevel returns the adjacent next Element at provided level if existed or nil otherwise.

func (*Element) Value

func (e *Element) Value() int64

Value returns the given Element value.

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

SkipList represents the list.

func New(maxLevel ...int) *SkipList

New creates a new skip list with provided maxLevel or defaultMaxLevel.

func (*SkipList) Front

func (list *SkipList) Front() *Element

Front returns the first element in the list.

func (*SkipList) Get

func (list *SkipList) Get(key string) *Element

Get searches element by provided key and returns the element if found or nil otherwise.

func (*SkipList) Len

func (list *SkipList) Len() int

Len returns the list length.

func (*SkipList) MaxLevel

func (list *SkipList) MaxLevel(level int) int

MaxLevel sets current max level of skip list and returns the previous max level. If level < 1, it does not set current max level.

func (*SkipList) Probability

func (list *SkipList) Probability(newProbability float64) float64

Probability sets the P value of skip list and returns the previous P. If newProbability < 0, it does not set current P.

func (*SkipList) Remove

func (list *SkipList) Remove(key string) *Element

Remove deletes the element with provided key from the list, and returns the removed element if found or nil otherwise.

func (*SkipList) Set

func (list *SkipList) Set(key string, value int64) *Element

Set upserts the value with provided key into the list and returns the element.


Generated by godoc2md