import "github.com/andy2046/gopie/pkg/skiplist"
Package skiplist provides a Skip List implementation.
- type Element
- type SkipList
- func New(maxLevel ...int) *SkipList
- func (list *SkipList) Front() *Element
- func (list *SkipList) Get(key string) *Element
- func (list *SkipList) Len() int
- func (list *SkipList) MaxLevel(level int) int
- func (list *SkipList) Probability(newProbability float64) float64
- func (list *SkipList) Remove(key string) *Element
- func (list *SkipList) Set(key string, value int64) *Element
type Element struct {
// contains filtered or unexported fields
}Element represents an element in the list.
func (e *Element) Key() stringKey returns the given Element key.
func (e *Element) Next() *ElementNext returns the adjacent next Element if existed or nil otherwise.
func (e *Element) NextLevel(level int) *ElementNextLevel returns the adjacent next Element at provided level if existed or nil otherwise.
func (e *Element) Value() int64Value returns the given Element value.
type SkipList struct {
// contains filtered or unexported fields
}SkipList represents the list.
func New(maxLevel ...int) *SkipListNew creates a new skip list with provided maxLevel or defaultMaxLevel.
func (list *SkipList) Front() *ElementFront returns the first element in the list.
func (list *SkipList) Get(key string) *ElementGet searches element by provided key and returns the element if found or nil otherwise.
func (list *SkipList) Len() intLen returns the list length.
func (list *SkipList) MaxLevel(level int) intMaxLevel 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) float64Probability sets the P value of skip list and returns the previous P.
If newProbability < 0, it does not set current P.
func (list *SkipList) Remove(key string) *ElementRemove deletes the element with provided key from the list, and returns the removed element if found or nil otherwise.
func (list *SkipList) Set(key string, value int64) *ElementSet upserts the value with provided key into the list and returns the element.
Generated by godoc2md