-
Notifications
You must be signed in to change notification settings - Fork 12
/
skiplist.go
45 lines (39 loc) · 899 Bytes
/
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
package main
import (
"errors"
"github.com/thomasjungblut/go-sstables/skiplist"
"log"
)
func main() {
skipListMap := skiplist.NewSkipListMap[int, int](skiplist.OrderedComparator[int]{})
skipListMap.Insert(13, 91)
skipListMap.Insert(3, 1)
skipListMap.Insert(5, 2)
log.Printf("size: %d", skipListMap.Size())
it, _ := skipListMap.Iterator()
for {
k, v, err := it.Next()
if errors.Is(err, skiplist.Done) {
break
}
log.Printf("key: %d, value: %d", k, v)
}
log.Printf("starting at key: %d", 5)
it, _ = skipListMap.IteratorStartingAt(5)
for {
k, v, err := it.Next()
if errors.Is(err, skiplist.Done) {
break
}
log.Printf("key: %d, value: %d", k, v)
}
log.Printf("between: %d and %d", 8, 50)
it, _ = skipListMap.IteratorBetween(8, 50)
for {
k, v, err := it.Next()
if errors.Is(err, skiplist.Done) {
break
}
log.Printf("key: %d, value: %d", k, v)
}
}