Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
021465e524
|
|||
cf9c73aa4a
|
|||
0652bf22dc
|
@@ -433,3 +433,10 @@ func ArrConcat[T any](arr ...[]T) []T {
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// ArrCopy does a shallow copy of the 'in' array
|
||||
func ArrCopy[T any](in []T) []T {
|
||||
out := make([]T, len(in))
|
||||
copy(out, in)
|
||||
return out
|
||||
}
|
||||
|
@@ -31,16 +31,16 @@ func CompareIntArr(arr1 []int, arr2 []int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func CompareArr[T OrderedConstraint](arr1 []T, arr2 []T) bool {
|
||||
func CompareArr[T OrderedConstraint](arr1 []T, arr2 []T) int {
|
||||
|
||||
for i := 0; i < len(arr1) || i < len(arr2); i++ {
|
||||
|
||||
if i < len(arr1) && i < len(arr2) {
|
||||
|
||||
if arr1[i] < arr2[i] {
|
||||
return true
|
||||
return -1
|
||||
} else if arr1[i] > arr2[i] {
|
||||
return false
|
||||
return +2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
@@ -49,15 +49,55 @@ func CompareArr[T OrderedConstraint](arr1 []T, arr2 []T) bool {
|
||||
|
||||
if i < len(arr1) {
|
||||
|
||||
return true
|
||||
return +1
|
||||
|
||||
} else { // if i < len(arr2)
|
||||
|
||||
return false
|
||||
return -1
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
func CompareString(a, b string) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return +1
|
||||
}
|
||||
|
||||
func CompareInt(a, b int) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return +1
|
||||
}
|
||||
|
||||
func CompareInt64(a, b int64) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return +1
|
||||
}
|
||||
|
||||
func Compare[T OrderedConstraint](a, b T) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return +1
|
||||
}
|
||||
|
Reference in New Issue
Block a user