github.com/andy2046/gopie@v0.7.0/pkg/skiplist/typestr.go (about) 1 // +build ignore 2 3 package skiplist 4 5 import ( 6 "math/rand" 7 "sync" 8 ) 9 10 type ( 11 elementNodeS struct { 12 forward []*ElementS 13 } 14 15 // ElementS represents an element in the list. 16 ElementS struct { 17 elementNodeS 18 key string 19 value string 20 } 21 22 // S represents the list. 23 S struct { 24 elementNodeS 25 randSource rand.Source 26 searchNodesCache []*elementNodeS 27 probability float64 28 probTable []float64 29 maxLevel int 30 length int 31 mutex sync.RWMutex 32 } 33 ) 34 35 // Key returns the given Element key. 36 func (e *ElementS) Key() string { 37 return e.key 38 } 39 40 // Value returns the given Element value. 41 func (e *ElementS) Value() string { 42 return e.value 43 } 44 45 // Next returns the adjacent next Element if existed or nil otherwise. 46 func (e *ElementS) Next() *ElementS { 47 return e.forward[0] 48 } 49 50 // NextLevel returns the adjacent next Element at provided level if existed or nil otherwise. 51 func (e *ElementS) NextLevel(level int) *ElementS { 52 if level >= len(e.forward) || level < 0 { 53 return nil 54 } 55 56 return e.forward[level] 57 }