mirror of
https://github.com/luxfi/utxo.git
synced 2026-10-30 15:13:57 +00:00
34 lines
616 B
Go
34 lines
616 B
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package utxo
|
|
|
|
import (
|
|
"cmp"
|
|
"slices"
|
|
)
|
|
|
|
func sortByCompare[T interface{ Compare(T) int }](s []T) {
|
|
slices.SortFunc(s, func(a, b T) int {
|
|
return a.Compare(b)
|
|
})
|
|
}
|
|
|
|
func isSortedAndUniqueByCompare[T interface{ Compare(T) int }](s []T) bool {
|
|
for i := 1; i < len(s); i++ {
|
|
if s[i-1].Compare(s[i]) >= 0 {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func isSortedAndUniqueOrdered[T cmp.Ordered](s []T) bool {
|
|
for i := 1; i < len(s); i++ {
|
|
if s[i-1] >= s[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|