mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-13 02:33:43 +08:00
feat: 增加了集合方法 差集、对称差集、交集 (#77)
This commit is contained in:
39
sliceUtil/setof_example_test.go
Normal file
39
sliceUtil/setof_example_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package sliceUtil
|
||||
|
||||
import "fmt"
|
||||
|
||||
func ExampleDiff() {
|
||||
s1 := []int64{1, 2, 5, 7}
|
||||
s2 := []int64{5, 6, 7}
|
||||
|
||||
diff := Diff(s1, s2)
|
||||
fmt.Println(diff)
|
||||
|
||||
// Output:
|
||||
// [1 2]
|
||||
}
|
||||
|
||||
// 演示 SymmetricDiff 函数的用法
|
||||
func ExampleSymmetricDiff() {
|
||||
s1 := []int64{1, 5, 7}
|
||||
s2 := []int64{5, 6, 7, 8, 9}
|
||||
s3 := []int64{9, 10, 11}
|
||||
|
||||
diff := SymmetricDiff(s1, s2, s3)
|
||||
fmt.Println(diff)
|
||||
|
||||
// Output:
|
||||
// [1 6 8 10 11]
|
||||
}
|
||||
|
||||
// 演示 ExampleIntersect 函数的用法
|
||||
func ExampleIntersect() {
|
||||
s1 := []int64{1, 5, 7}
|
||||
s2 := []int64{5, 6, 7, 8, 9}
|
||||
|
||||
diff := Intersect(s1, s2)
|
||||
fmt.Println(diff)
|
||||
|
||||
// Output:
|
||||
// [5 7]
|
||||
}
|
Reference in New Issue
Block a user