Every line of 'golang compare slices' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
2707 func deriveCompareSliceOfbool(this, that []bool) int { 2708 if this == nil { 2709 if that == nil { 2710 return 0 2711 } 2712 return -1 2713 } 2714 if that == nil { 2715 return 1 2716 } 2717 if len(this) != len(that) { 2718 if len(this) < len(that) { 2719 return -1 2720 } 2721 return 1 2722 } 2723 for i := 0; i < len(this); i++ { 2724 if c := deriveComparebool(this[i], that[i]); c != 0 { 2725 return c 2726 } 2727 } 2728 return 0 2729 }
121 func SliceUintDiff(a, b []uint, cb func(uint)) { 122 for i := 0; i < len(a); i++ { 123 found := false 124 for j := 0; j < len(b); j++ { 125 if a[i] == b[j] { 126 found = true 127 break 128 } 129 } 130 if !found && cb != nil { 131 cb(a[i]) 132 } 133 } 134 }
565 func compareSlice(sliceA []interface{}, sliceB []interface{}) bool { 566 var ifMatched bool 567 ifMatched = true 568 for i, valueA := range sliceA { 569 // if valueA != sliceB[i] { 570 if !reflect.DeepEqual(valueA, sliceB[i]) { 571 ifMatched = false 572 break 573 } 574 } 575 return ifMatched 576 }
2731 func deriveCompareSliceOfcomplex128(this, that []complex128) int { 2732 if this == nil { 2733 if that == nil { 2734 return 0 2735 } 2736 return -1 2737 } 2738 if that == nil { 2739 return 1 2740 } 2741 if len(this) != len(that) { 2742 if len(this) < len(that) { 2743 return -1 2744 } 2745 return 1 2746 } 2747 for i := 0; i < len(this); i++ { 2748 if c := deriveCompareComplex64(this[i], that[i]); c != 0 { 2749 return c 2750 } 2751 } 2752 return 0 2753 }
855 func uniqueSlices(a, b reflect.Value) (bool, error) { 856 if !util.IsValueSlice(a) || !util.IsValueSlice(b) { 857 return false, fmt.Errorf("a and b must both be slices, got a: %v, b: %v", a.Type().Kind(), b.Type().Kind()) 858 } 859 860 if a.Type().Elem() != b.Type().Elem() { 861 return false, fmt.Errorf("a and b do not contain the same type, got a: %v, b: %v", a.Type().Elem().Kind(), b.Type().Elem().Kind()) 862 } 863 864 for i := 0; i < a.Len(); i++ { 865 for j := 0; j < b.Len(); j++ { 866 if cmp.Equal(a.Index(i).Interface(), b.Index(j).Interface()) { 867 return false, nil 868 } 869 } 870 } 871 return true, nil 872 }
156 func StartCompare(lhs []byte, rhs []byte) int { 157 if lhs == nil && rhs == nil { 158 return 0 159 } 160 161 if lhs == nil { 162 return -1 163 } 164 165 if rhs == nil { 166 return 1 167 } 168 169 return bytes.Compare(lhs, rhs) 170 }
2438 func deriveCompareuint8(this, that uint8) int { 2439 if this != that { 2440 if this < that { 2441 return -1 2442 } else { 2443 return 1 2444 } 2445 } 2446 return 0 2447 }
18 func Compare(first, second core.Type) int64 { 19 f, ok := typeComparisonTable[first] 20 21 // custom type 22 if !ok { 23 return -1 24 } 25 26 s, ok := typeComparisonTable[second] 27 28 // custom type 29 if !ok { 30 return 1 31 } 32 33 if f == s { 34 return 0 35 } 36 37 if f > s { 38 return 1 39 } 40 41 return -1 42 }
23 func sortSliceByColumnIndexInt(s [][]string, columnIndex int, direction string) [][]string { 24 if columnIndex == 0 { 25 log.Fatalf("Error occurred. Please check map of columns indexes") 26 } 27 sort.Slice(s, func(i, j int) bool { 28 firstCellValue, _ := strconv.Atoi(s[i][columnIndex]) 29 secondCellValue, _ := strconv.Atoi(s[j][columnIndex]) 30 if direction == "desc" { 31 return firstCellValue > secondCellValue 32 } 33 return firstCellValue < secondCellValue 34 }) 35 return s 36 }
572 func (d *Datum) compareBytes(sc *variable.StatementContext, b []byte) (int, error) { 573 return d.compareString(sc, hack.String(b)) 574 }