|
@@ -398,3 +398,116 @@ func GetUserLoginInfo(ctx *context.Context) map[string]interface{} {
|
|
|
l["platform"] = ua.Platform()
|
|
|
return l
|
|
|
}
|
|
|
+
|
|
|
+func StringListCompare(list1, list2 []string) (isEqual bool, common, onlyList1, onlyList2 []string) {
|
|
|
+ if len(list1) != len(list2) {
|
|
|
+ isEqual = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建map来存储list1列表中的元素
|
|
|
+ AMap := make(map[string]int)
|
|
|
+ for _, item := range list1 {
|
|
|
+ AMap[item]++
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查B列表中的元素是否在AMap中
|
|
|
+ for _, item := range list2 {
|
|
|
+ if count, exists := AMap[item]; !exists || count == 0 {
|
|
|
+ isEqual = false
|
|
|
+ }
|
|
|
+ AMap[item]--
|
|
|
+ }
|
|
|
+ if !isEqual {
|
|
|
+ // 创建一个map来存储A列表中的元素
|
|
|
+ list1Map := make(map[string]struct{})
|
|
|
+ for _, a := range list1 {
|
|
|
+ list1Map[a] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找list2列表中存在但list1列表中不存在的元素
|
|
|
+ for _, v := range list2 {
|
|
|
+ if _, exists := list1Map[v]; !exists {
|
|
|
+ onlyList2 = append(onlyList2, v)
|
|
|
+ } else {
|
|
|
+ common = append(common, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个map来存储B列表中的元素
|
|
|
+ list2Map := make(map[string]struct{})
|
|
|
+ for _, b := range list2 {
|
|
|
+ list2Map[b] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找list1列表中存在但list2列表中不存在的元素
|
|
|
+ for _, a := range list1 {
|
|
|
+ if _, exists := list2Map[a]; !exists {
|
|
|
+ onlyList1 = append(onlyList1, a)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ isEqual = true
|
|
|
+ return
|
|
|
+}
|
|
|
+func IntListCompare(list1, list2 []int) (isEqual bool, common, onlyList1, onlyList2 []int) {
|
|
|
+ if len(list1) != len(list2) {
|
|
|
+ isEqual = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建map来存储list1列表中的元素
|
|
|
+ AMap := make(map[int]int)
|
|
|
+ for _, item := range list1 {
|
|
|
+ AMap[item]++
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查B列表中的元素是否在AMap中
|
|
|
+ for _, item := range list2 {
|
|
|
+ if count, exists := AMap[item]; !exists || count == 0 {
|
|
|
+ isEqual = false
|
|
|
+ }
|
|
|
+ AMap[item]--
|
|
|
+ }
|
|
|
+ if !isEqual {
|
|
|
+ // 创建一个map来存储A列表中的元素
|
|
|
+ list1Map := make(map[int]struct{})
|
|
|
+ for _, a := range list1 {
|
|
|
+ list1Map[a] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找list2列表中存在但list1列表中不存在的元素
|
|
|
+ for _, v := range list2 {
|
|
|
+ if _, exists := list1Map[v]; !exists {
|
|
|
+ onlyList2 = append(onlyList2, v)
|
|
|
+ } else {
|
|
|
+ common = append(common, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个map来存储B列表中的元素
|
|
|
+ list2Map := make(map[int]struct{})
|
|
|
+ for _, b := range list2 {
|
|
|
+ list2Map[b] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找list1列表中存在但list2列表中不存在的元素
|
|
|
+ for _, a := range list1 {
|
|
|
+ if _, exists := list2Map[a]; !exists {
|
|
|
+ onlyList1 = append(onlyList1, a)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ isEqual = true
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func ChunkBy[T any](list []T, size int) [][]T {
|
|
|
+ var chunks [][]T
|
|
|
+ for size < len(list) {
|
|
|
+ list, chunks = list[size:], append(chunks, list[0:size:size])
|
|
|
+ }
|
|
|
+ return append(chunks, list)
|
|
|
+}
|