-
Notifications
You must be signed in to change notification settings - Fork 0
/
armap_example_test.go
89 lines (68 loc) · 1.46 KB
/
armap_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package armap
import (
"fmt"
)
func ExampleMap() {
a := NewArena(1024*1024, 2) // 2MB arena size
defer a.Release()
m := NewMap[string, string](a, WithCapacity(1000))
m.Set("hello", "world1")
v, ok := m.Get("hello")
fmt.Println(v, ok)
m.Set("hello", "world2")
v, ok = m.Get("hello")
fmt.Println(v, ok)
m.Clear()
_, ok = m.Get("hello")
fmt.Println(ok)
// Output:
// world1 true
// world2 true
// false
}
func ExampleSet() {
a := NewArena(1024*1024, 2) // 2MB arena size
defer a.Release()
s := NewSet[string](a, WithCapacity(1000))
ok := s.Add("foo")
fmt.Println("exists foo =", ok)
ok = s.Add("bar")
fmt.Println("exists bar =", ok)
ok = s.Contains("foo")
fmt.Println("contains foo =", ok)
ok = s.Add("foo")
fmt.Println("exists foo =", ok)
s.Clear()
ok = s.Add("foo")
fmt.Println("exists foo =", ok)
// Output:
// exists foo = false
// exists bar = false
// contains foo = true
// exists foo = true
// exists foo = false
}
func ExampleLinkedList() {
a := NewArena(1024*1024, 2) // 2MB arena size
defer a.Release()
l := NewLinkedList[string, string](a)
l.Push("hello1", "world1")
v, ok := l.Get("hello1")
fmt.Println(v, ok)
l.Push("hello2", "world2")
v, ok = l.Get("hello2")
fmt.Println(v, ok)
l.Scan(func(key string, value string) bool {
fmt.Println(key, value)
return true
})
l.Clear()
_, ok = l.Get("hello1")
fmt.Println(ok)
// Output:
// world1 true
// world2 true
// hello2 world2
// hello1 world1
// false
}