-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiplist.go
66 lines (54 loc) · 1.12 KB
/
skiplist.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package orderedmap
import "github.com/ryszard/goskiplist/skiplist"
type skiplistOrderedMap struct {
sl *skiplist.SkipList
}
func NewSkipList(lesser func(l, r interface{}) bool) *skiplistOrderedMap {
return &skiplistOrderedMap{skiplist.NewCustomMap(lesser)}
}
func (me *skiplistOrderedMap) Set(key interface{}, value interface{}) {
me.sl.Set(key, value)
}
func (me *skiplistOrderedMap) Get(key interface{}) interface{} {
if me == nil {
return nil
}
ret, _ := me.sl.Get(key)
return ret
}
func (me *skiplistOrderedMap) GetOk(key interface{}) (interface{}, bool) {
if me == nil {
return nil, false
}
return me.sl.Get(key)
}
type Iter struct {
it skiplist.Iterator
}
func (me *Iter) Next() bool {
if me == nil {
return false
}
return me.it.Next()
}
func (me *Iter) Value() interface{} {
return me.it.Value()
}
func (me *skiplistOrderedMap) Iter() *Iter {
if me == nil {
return nil
}
return &Iter{me.sl.Iterator()}
}
func (me *skiplistOrderedMap) Unset(key interface{}) {
if me == nil {
return
}
me.sl.Delete(key)
}
func (me *skiplistOrderedMap) Len() int {
if me.sl == nil {
return 0
}
return me.sl.Len()
}