import "github.com/byte-mug/golibs/skiplist"
Skip List implement in Go.
A Skip List is a data structure that allows fast search within an ordered sequence of elements. Fast search is made possible by maintaining a linked hierarchy of subsequences, each skipping over fewer elements.
const ( DefaultMaxLevel int = 15 //Maximal level allow to create in this skip list DefaultPropobility float32 = 0.25 //Default propobility )
-
type Skiplist struct { Header *Skipnode // List configuration MaxLevel int Propobility float32 // List Comparison Comparator utils.Comparator // List status Level int //current level of whole skiplist Random *rand.Rand }
-
func NewSkipList(comparator utils.Comparator) *Skiplist
NewSkipList : Init structure for Skit List.
func (b *Skiplist) Delete(searchKey interface{}) error
Delete: Delete element by search key
func (b *Skiplist) DisplayAll()
DisplayAll: Display current SkipList content in console, will also print out the linked pointer.
func (b *Skiplist) Insert(searchKey interface{}, value interface{})
Insert: Insert a search key and its value which could be interface.
func (b *Skiplist) RandomLevel() int
-
func (b *Skiplist) Search(searchKey interface{}) (interface{}, error)
Search: Search a element by search key and return the interface{}
func (b *Skiplist) SetMaxLevel(maxLevel int)
Change SkipList default maxlevel is 4.
type Skipnode struct { Key interface{} Val interface{} Forward []*Skipnode Level int // contains filtered or unexported fields }
-
func NewHeader(createLevel int, maxLevel int) *Skipnode
-
func NewNode(searchKey interface{}, value interface{}, createLevel int, maxLevel int) *Skipnode
-
import "errors"
import "fmt"
import "github.com/emirpasic/gods/utils"
import "math/rand"
import "time"