diff --git a/docs/maputil.md b/docs/maputil.md index 75c62db..cd8bd73 100644 --- a/docs/maputil.md +++ b/docs/maputil.md @@ -27,6 +27,7 @@ import ( - [Merge](#Merge) - [Minus](#Minus) - [Values](#Values) +- [Values](#Values)
@@ -303,13 +304,13 @@ func main() { } ``` -### Values -Returns a boolean
+### IsDisjoint +Checks two are disjoint if they have no keys in common
Signature: ```go -IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool +func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool ``` Example: @@ -337,18 +338,15 @@ func main() { 4: "c", 5: "d", } - + m3 := map[int]string{ 6: "a", } ok := maputil.IsDisjoint(m2, m1) - fmt.Println(ok) // false - ok = maputil.IsDisjoint(m2, m3) - fmt.Println(ok) // true } ``` \ No newline at end of file diff --git a/docs/maputil_zh-CN.md b/docs/maputil_zh-CN.md index 5fed2f4..46be0b6 100644 --- a/docs/maputil_zh-CN.md +++ b/docs/maputil_zh-CN.md @@ -231,7 +231,6 @@ func main() { - ### Minus返回一个map,其中的key存在于mapA,不存在于mapB.
@@ -301,4 +300,52 @@ func main() { fmt.Println(values) // []string{"a", "a", "b", "c", "d"} } +``` + + +### IsDisjoint +验证两个map是否具有不同的key
+ +函数签名: + +```go +func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool +``` +例子: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/maputil" +) + +func main() { + m1 := map[int]string{ + 1: "a", + 2: "a", + 3: "b", + 4: "c", + 5: "d", + } + + m2 := map[int]string{ + 1: "a", + 2: "a", + 3: "b", + 4: "c", + 5: "d", + } + + m3 := map[int]string{ + 6: "a", + } + + ok := maputil.IsDisjoint(m2, m1) + fmt.Println(ok) // false + + ok = maputil.IsDisjoint(m2, m3) + fmt.Println(ok) // true +} ``` \ No newline at end of file