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() string
Key returns the given Element key.
func (e *Element) Next() *Element
Next returns the adjacent next Element if existed or nil otherwise.
func (e *Element) NextLevel(level int) *Element
NextLevel returns the adjacent next Element at provided level if existed or nil otherwise.
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 (list *SkipList) Front() *Element
Front returns the first element in the list.
func (list *SkipList) Get(key string) *Element
Get searches element by provided key and returns the element if found or nil otherwise.
func (list *SkipList) Len() int
Len returns the list length.
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 (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 (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