forked from chen3feng/skiplist-survey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gostl.go
90 lines (66 loc) · 1.55 KB
/
gostl.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"math"
"time"
liyue201 "github.com/liyue201/gostl/ds/skiplist"
)
func liyue201New(n int) *liyue201.Skiplist {
// gostl's default level is only 10, so we must increase it to fit the test size
return liyue201.New(liyue201.WithMaxLevel(int(math.Ceil(math.Log2(float64(n))))))
}
func liyue201Inserts(n int) {
list := liyue201New(n)
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
list.Insert(n-i, testByteString)
}
}
func liyue201WorstInserts(n int) {
list := liyue201New(n)
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
list.Insert(i, testByteString)
}
}
func liyue201AvgSearch(n int) {
list := liyue201New(n)
for i := 0; i < n; i++ {
list.Insert(i, testByteString)
}
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
_ = list.Get(i)
}
}
func liyue201SearchEnd(n int) {
list := liyue201New(n)
for i := 0; i < n; i++ {
list.Insert(i, testByteString)
}
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
_ = list.Get(n)
}
}
func liyue201Delete(n int) {
list := liyue201New(n)
for i := 0; i < n; i++ {
list.Insert(i, testByteString)
}
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
_ = list.Remove(i)
}
}
func liyue201WorstDelete(n int) {
list := liyue201New(n)
for i := 0; i < n; i++ {
list.Insert(i, testByteString)
}
defer timeTrack(time.Now(), n)
for i := 0; i < n; i++ {
_ = list.Remove(n - i)
}
}
var liyue201Functions = []func(int){liyue201Inserts, liyue201WorstInserts,
liyue201AvgSearch, liyue201SearchEnd, liyue201Delete, liyue201WorstDelete}