-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_example_test.go
70 lines (59 loc) · 1.56 KB
/
list_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package skiplist
import (
"fmt"
"reflect"
)
func ExampleNewList() {
l := NewList()
fmt.Println("Max level:", l.MaxLevel)
// Output:
// Max level: 32
}
func ExampleNewListWithLevel() {
l := NewListWithLevel(200)
fmt.Println("Max level:", l.MaxLevel)
// Output:
// Max level: 200
}
func ExampleList_Insert() {
l := NewList()
l.Insert(1, []byte("example 1"))
l.Insert(2, []byte("example 2"))
l.Insert(3, []byte("example 3"))
l.Insert(4, []byte("example 4"))
fmt.Println("Size:", l.Size())
// Output:
// Size: 4
}
func ExampleList_Search() {
l := NewList()
l.Insert(1, []byte("example 1"))
l.Insert(2, []byte("example 2"))
l.Insert(3, []byte("example 3"))
l.Insert(4, []byte("example 4"))
// Not Found
notFound := l.Search(45)
found := l.Search(4)
fmt.Printf("Searched for 45 and got %+v\n", notFound)
fmt.Printf("Searched for 4 and got '%+v'\n", string(reflect.ValueOf(found.Value()).Bytes()))
// Output:
// Searched for 45 and got <nil>
// Searched for 4 and got 'example 4'
}
func ExampleList_Delete() {
l := NewList()
l.Insert(1, []byte("example 1"))
l.Insert(2, []byte("example 2"))
l.Insert(3, []byte("example 3"))
l.Insert(4, []byte("example 4"))
found := l.Search(4)
fmt.Printf("Searched for 4 and got '%+v'\n", string(reflect.ValueOf(found.Value()).Bytes()))
// Delete node
fmt.Printf("Deleted key 4? %+v\n", l.Delete(4))
notFound := l.Search(4)
fmt.Printf("Searched for deleted key of 4 and got %+v\n", notFound)
// Output:
// Searched for 4 and got 'example 4'
// Deleted key 4? true
// Searched for deleted key of 4 and got <nil>
}