slices: consistently use E rather than Elem
This doesn't change the generated file, that will come later.
For golang/go#51698
Change-Id: I3ee637dc1ec94f0c23de21fa0a4a398d31a5b70e
Reviewed-on: https://go-review.googlesource.com/c/exp/+/393378
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eli Benderskyā€ˇ <eliben@golang.org>
diff --git a/slices/slices_test.go b/slices/slices_test.go
index 14ae6b8..efe9966 100644
--- a/slices/slices_test.go
+++ b/slices/slices_test.go
@@ -82,7 +82,7 @@
}
// offByOne returns true if integers v1 and v2 differ by 1.
-func offByOne[Elem constraints.Integer](v1, v2 Elem) bool {
+func offByOne[E constraints.Integer](v1, v2 E) bool {
return v1 == v2+1 || v1 == v2-1
}
diff --git a/slices/sort.go b/slices/sort.go
index ed9f41a..b2035ab 100644
--- a/slices/sort.go
+++ b/slices/sort.go
@@ -7,26 +7,26 @@
import "golang.org/x/exp/constraints"
// Sort sorts a slice of any ordered type in ascending order.
-func Sort[Elem constraints.Ordered](x []Elem) {
+func Sort[E constraints.Ordered](x []E) {
n := len(x)
quickSortOrdered(x, 0, n, maxDepth(n))
}
// Sort sorts the slice x in ascending order as determined by the less function.
// This sort is not guaranteed to be stable.
-func SortFunc[Elem any](x []Elem, less func(a, b Elem) bool) {
+func SortFunc[E any](x []E, less func(a, b E) bool) {
n := len(x)
quickSortLessFunc(x, 0, n, maxDepth(n), less)
}
// SortStable sorts the slice x while keeping the original order of equal
// elements, using less to compare elements.
-func SortStableFunc[Elem any](x []Elem, less func(a, b Elem) bool) {
+func SortStableFunc[E any](x []E, less func(a, b E) bool) {
stableLessFunc(x, len(x), less)
}
// IsSorted reports whether x is sorted in ascending order.
-func IsSorted[Elem constraints.Ordered](x []Elem) bool {
+func IsSorted[E constraints.Ordered](x []E) bool {
for i := len(x) - 1; i > 0; i-- {
if x[i] < x[i-1] {
return false
@@ -37,7 +37,7 @@
// IsSortedFunc reports whether x is sorted in ascending order, with less as the
// comparison function.
-func IsSortedFunc[Elem any](x []Elem, less func(a, b Elem) bool) bool {
+func IsSortedFunc[E any](x []E, less func(a, b E) bool) bool {
for i := len(x) - 1; i > 0; i-- {
if less(x[i], x[i-1]) {
return false
@@ -51,7 +51,7 @@
// which it could be inserted into the slice is returned; therefore, if the
// intention is to find target itself a separate check for equality with the
// element at the returned index is required.
-func BinarySearch[Elem constraints.Ordered](x []Elem, target Elem) int {
+func BinarySearch[E constraints.Ordered](x []E, target E) int {
return search(len(x), func(i int) bool { return x[i] >= target })
}
@@ -63,7 +63,7 @@
// the first true index. If there is no such index, BinarySearchFunc returns n.
// (Note that the "not found" return value is not -1 as in, for instance,
// strings.Index.) Search calls ok(i) only for i in the range [0, n).
-func BinarySearchFunc[Elem any](x []Elem, ok func(Elem) bool) int {
+func BinarySearchFunc[E any](x []E, ok func(E) bool) int {
return search(len(x), func(i int) bool { return ok(x[i]) })
}