-
Notifications
You must be signed in to change notification settings - Fork 52
/
type.go
43 lines (36 loc) · 833 Bytes
/
type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package skiplist
import (
"math/rand"
"sync"
)
type elementNode struct {
next []*Element
}
type Element struct {
elementNode
key float64
value interface{}
}
// Key allows retrieval of the key for a given Element
func (e *Element) Key() float64 {
return e.key
}
// Value allows retrieval of the value for a given Element
func (e *Element) Value() interface{} {
return e.value
}
// Next returns the following Element or nil if we're at the end of the list.
// Only operates on the bottom level of the skip list (a fully linked list).
func (element *Element) Next() *Element {
return element.next[0]
}
type SkipList struct {
elementNode
maxLevel int
Length int
randSource rand.Source
probability float64
probTable []float64
mutex sync.RWMutex
prevNodesCache []*elementNode
}