package main
import (
"fmt"
mapset "github.com/deckarep/golang-set"
)
func main() {
fmt.Println("Hello world")
s1 := mapset.NewSet(1, 2, 3, 4)
fmt.Println("s1 contains 3: ", s1.Contains(3)) //true
fmt.Println("s1 contains 5: ", s1.Contains(5)) //false
s1.Add("poloxue")
fmt.Println("s1 contains poloxue: ", s1.Contains("poloxue")) //true
s1.Remove(3)
fmt.Println("s1 contains 3: ", s1.Contains(3)) //false
s2 := mapset.NewSet(1, 3, 4, 5)
// 并集
fmt.Println(s1.Union(s2)) // Set{poloxue, 3, 5, 1, 2, 4}
set1 := mapset.NewSet(1, 2, 3)
set2 := mapset.NewSet(1, 2, 3)
fmt.Println(set1.Equal(set2)) // true
set2.Remove(1)
fmt.Println(set1.Equal(set2)) // false
set2.Add(1)
fmt.Println(set1.Equal(set2)) // true
}
Golang中的Set
最新推荐文章于 2024-05-10 09:36:13 发布