代码拉取完成,页面将自动刷新
package utils
import "sort"
/**
* slice(string类型)元素去重
*/
func RemoveReplicaSliceString(slc []string) []string {
result := make([]string, 0)
tempMap := make(map[string]bool, len(slc))
for _, e := range slc {
if tempMap[e] == false {
tempMap[e] = true
result = append(result, e)
}
}
return result
}
/**
* slice(int类型)元素去重
*/
func RemoveReplicaSliceInt(slc []int) []int {
result := make([]int, 0)
tempMap := make(map[int]bool, len(slc))
for _, e := range slc {
if tempMap[e] == false {
tempMap[e] = true
result = append(result, e)
}
}
return result
}
// CompareIntSlice 比较两个int型切片是否相等, true:相等, false:不相等
func CompareIntSlice(a, b []int) bool {
if len(a) != len(b) {
return false
}
if (a == nil) != (b == nil) {
return false
}
sort.Ints(a[:])
sort.Ints(b[:])
for key, value := range a {
if value != b[key] {
return false
}
}
return true
}
//值是否存在
func IsSliceString(val string, slice []string) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
//值是否存在
func IsSliceInt64(val int64, slice []int64) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
func IsSliceInt(val int, slice []int) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。