-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg_test.go
58 lines (48 loc) · 913 Bytes
/
pkg_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
package ordered
import "fmt"
func ExampleOrderedMap() {
data := NewMap[int, string]()
data.Set(1, "one")
data.Set(3, "three")
data.Set(2, "two")
data.Set(-1, "neg one")
data.Del(1)
for _, key := range data.Keys() {
value, _ := data.Get(key)
fmt.Println(key, value)
}
data.Range(func(key int, value string) bool {
fmt.Println(key, value)
return true
})
// Output:
// 3 three
// 2 two
// -1 neg one
// 3 three
// 2 two
// -1 neg one
}
func ExampleOrderedSet() {
set1 := NewSet[int]()
set1.Add(1)
set1.Add(3)
set1.Add(2)
set1.Add(4)
set1.Del(1)
fmt.Println(set1.Elements())
set2 := NewSet[int]()
set2.Add(3)
set2.Add(4)
set2.Add(5)
fmt.Println(set2.Elements())
fmt.Println(set1.Union(set2).Elements())
fmt.Println(set1.Intersection(set2).Elements())
fmt.Println(set1.Difference(set2).Elements())
// Output:
// [3 2 4]
// [3 4 5]
// [3 2 4 5]
// [3 4]
// [2]
}