-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_test.go
54 lines (43 loc) · 965 Bytes
/
example_test.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
package skiplist_test
import (
"fmt"
. "github.com/kkdai/skiplist"
)
func ExampleNewSkipList() {
//New a skiplist
sl := NewSkipList()
sl.DisplayAll()
}
func ExampleSkiplist_Insert() {
//New a skiplist
sl := NewSkipList()
//Insert search key 50, value "5", value could be anything.
sl.Insert(50, "5")
}
func ExampleSkiplist_Search() {
//New a skiplist
sl := NewSkipList()
//Insert search key 50, value "5", value could be anything.
sl.Insert(50, "5")
sl.Insert(40, "4")
sl.Insert(70, "7")
sl.Insert(100, "10")
//Search key, which time complexity O(log n)
ret, err := sl.Search(50)
if err == nil {
fmt.Println("key 50: val->", ret)
} else {
fmt.Println("Not found, ", err)
}
}
func ExampleSkiplist_Delete() {
//New a skiplist
sl := NewSkipList()
//Insert search key 50, value "5", value could be anything.
sl.Insert(70, "7")
//Delete by search key
err := sl.Delete(70)
if err != nil {
fmt.Println("Delete not found")
}
}