-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_test.go
63 lines (46 loc) · 843 Bytes
/
examples_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
package syncmap_test
import (
"fmt"
"github.com/mdawar/syncmap"
)
func Example() {
m := syncmap.New[string, int]()
m.Set("a", 1)
m.Set("b", 2)
m.Delete("b")
fmt.Println(m.Len())
fmt.Println(m.Get("a"))
fmt.Println(m.Get("b"))
m.Clear()
fmt.Println(m.Len())
// Output:
// 1
// 1 true
// 0 false
// 0
}
func ExampleNewWithCapacity() {
// Create a map with a capacity hint.
m := syncmap.NewWithCapacity[string, int](10_000)
m.Set("a", 1)
fmt.Println(m.Len())
fmt.Println(m.Get("a"))
fmt.Println(m.Get("b"))
// Output:
// 1
// 1 true
// 0 false
}
func ExampleMap_All() {
m := syncmap.New[string, int]()
m.Set("a", 1)
m.Set("b", 2)
m.Set("c", 3)
for k, v := range m.All() {
fmt.Println("Key:", k, "-", "Value:", v)
}
// Output:
// Key: a - Value: 1
// Key: b - Value: 2
// Key: c - Value: 3
}