Merge "Use ordered interface from cmp package" into main am: 73b1b48d9b

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2937805

Change-Id: I316ffda88ce0d8ec1d7e4328c72b6d31630eb551
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2024-01-31 00:22:48 +00:00
committed by Automerger Merge Worker
2 changed files with 4 additions and 9 deletions

View File

@@ -15,6 +15,7 @@
package android
import (
"cmp"
"fmt"
"path/filepath"
"reflect"
@@ -106,15 +107,8 @@ func SortedStringKeys[V any](m map[string]V) []string {
return SortedKeys(m)
}
type Ordered interface {
~string |
~float32 | ~float64 |
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
// SortedKeys returns the keys of the given map in the ascending order.
func SortedKeys[T Ordered, V any](m map[T]V) []T {
func SortedKeys[T cmp.Ordered, V any](m map[T]V) []T {
if len(m) == 0 {
return nil
}

View File

@@ -15,6 +15,7 @@
package android
import (
"cmp"
"fmt"
"reflect"
"strconv"
@@ -650,7 +651,7 @@ func BenchmarkFirstUniqueStrings(b *testing.B) {
}
}
func testSortedKeysHelper[K Ordered, V any](t *testing.T, name string, input map[K]V, expected []K) {
func testSortedKeysHelper[K cmp.Ordered, V any](t *testing.T, name string, input map[K]V, expected []K) {
t.Helper()
t.Run(name, func(t *testing.T) {
actual := SortedKeys(input)