mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-12 16:52:29 +08:00
doc: format code in markdown file
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
|||||||
- [Merge](#Merge)
|
- [Merge](#Merge)
|
||||||
- [Minus](#Minus)
|
- [Minus](#Minus)
|
||||||
- [Values](#Values)
|
- [Values](#Values)
|
||||||
|
- [Values](#Values)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -303,13 +304,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="Values">Values</span>
|
### <span id="IsDisjoint">IsDisjoint</span>
|
||||||
<p>Returns a boolean</p>
|
<p>Checks two are disjoint if they have no keys in common</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
||||||
```
|
```
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
|
|
||||||
@@ -343,12 +344,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ok := maputil.IsDisjoint(m2, m1)
|
ok := maputil.IsDisjoint(m2, m1)
|
||||||
|
|
||||||
fmt.Println(ok) // false
|
fmt.Println(ok) // false
|
||||||
|
|
||||||
|
|
||||||
ok = maputil.IsDisjoint(m2, m3)
|
ok = maputil.IsDisjoint(m2, m3)
|
||||||
|
|
||||||
fmt.Println(ok) // true
|
fmt.Println(ok) // true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -231,7 +231,6 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Minus">Minus</span>
|
### <span id="Minus">Minus</span>
|
||||||
<p>返回一个map,其中的key存在于mapA,不存在于mapB.</p>
|
<p>返回一个map,其中的key存在于mapA,不存在于mapB.</p>
|
||||||
|
|
||||||
@@ -302,3 +301,51 @@ func main() {
|
|||||||
fmt.Println(values) // []string{"a", "a", "b", "c", "d"}
|
fmt.Println(values) // []string{"a", "a", "b", "c", "d"}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="IsDisjoint">IsDisjoint</span>
|
||||||
|
<p>验证两个map是否具有不同的key</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```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
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user