array.go
1.2 KB
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
59
60
61
62
63
64
65
package utils
import (
"fmt"
"strings"
)
type ArrayCmpare interface {
}
//ArrayInt64Diff 返回切片的差集:arr1-arr2
func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 {
if len(arr2) == 0 {
return arr1
}
setmap := make(map[int64]bool)
for i := range arr2 {
setmap[arr2[i]] = true
}
var result []int64
for i := range arr1 {
if _, ok := setmap[arr1[i]]; !ok {
result = append(result, arr1[i])
}
}
return result
}
//ArrayIntDiff 返回切片的差集:arr1-arr2
func ArrayIntDiff(arr1 []int, arr2 []int) []int {
if len(arr2) == 0 {
return arr1
}
setmap := make(map[int]bool)
for i := range arr2 {
setmap[arr2[i]] = true
}
var result []int
for i := range arr1 {
if _, ok := setmap[arr1[i]]; !ok {
result = append(result, arr1[i])
}
}
return result
}
//ArrayStringIn 检查s字符串是否在切片sl中
func ArrayStringIn(arr1 []string, s string) bool {
for _, v := range arr1 {
if strings.Compare(v, s) == 0 {
return true
}
}
return false
}
func JoinInt64s(ids []int64, spilt string) string {
var idStrings []string = make([]string, len(ids))
for i := 0; i < len(ids); i++ {
idStrings[i] = fmt.Sprintf("%v", ids[i])
}
return strings.Join(idStrings, spilt)
}