summaryrefslogtreecommitdiff
path: root/src/pkg/sort
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/sort')
-rw-r--r--src/pkg/sort/search.go12
-rw-r--r--src/pkg/sort/search_test.go6
-rw-r--r--src/pkg/sort/sort.go20
-rw-r--r--src/pkg/sort/sort_test.go20
4 files changed, 29 insertions, 29 deletions
diff --git a/src/pkg/sort/search.go b/src/pkg/sort/search.go
index b3ddd2dfa..6828e19b6 100644
--- a/src/pkg/sort/search.go
+++ b/src/pkg/sort/search.go
@@ -74,7 +74,7 @@ func Search(n int, f func(int) bool) int {
// Convenience wrappers for common cases.
-// SearchInts searches x in a sorted slice of ints and returns the index
+// SearchInts searches for x in a sorted slice of ints and returns the index
// as specified by Search. The array must be sorted in ascending order.
//
func SearchInts(a []int, x int) int {
@@ -82,15 +82,15 @@ func SearchInts(a []int, x int) int {
}
-// SearchFloats searches x in a sorted slice of floats and returns the index
+// SearchFloat64s searches for x in a sorted slice of float64s and returns the index
// as specified by Search. The array must be sorted in ascending order.
//
-func SearchFloats(a []float, x float) int {
+func SearchFloat64s(a []float64, x float64) int {
return Search(len(a), func(i int) bool { return a[i] >= x })
}
-// SearchStrings searches x in a sorted slice of strings and returns the index
+// SearchStrings searches for x in a sorted slice of strings and returns the index
// as specified by Search. The array must be sorted in ascending order.
//
func SearchStrings(a []string, x string) int {
@@ -102,8 +102,8 @@ func SearchStrings(a []string, x string) int {
func (p IntArray) Search(x int) int { return SearchInts(p, x) }
-// Search returns the result of applying SearchFloats to the receiver and x.
-func (p FloatArray) Search(x float) int { return SearchFloats(p, x) }
+// Search returns the result of applying SearchFloat64s to the receiver and x.
+func (p Float64Array) Search(x float64) int { return SearchFloat64s(p, x) }
// Search returns the result of applying SearchStrings to the receiver and x.
diff --git a/src/pkg/sort/search_test.go b/src/pkg/sort/search_test.go
index e16e2c93f..939f66af3 100644
--- a/src/pkg/sort/search_test.go
+++ b/src/pkg/sort/search_test.go
@@ -96,7 +96,7 @@ func TestSearchEfficiency(t *testing.T) {
// Smoke tests for convenience wrappers - not comprehensive.
-var fdata = []float{0: -3.14, 1: 0, 2: 1, 3: 2, 4: 1000.7}
+var fdata = []float64{0: -3.14, 1: 0, 2: 1, 3: 2, 4: 1000.7}
var sdata = []string{0: "f", 1: "foo", 2: "foobar", 3: "x"}
var wrappertests = []struct {
@@ -105,10 +105,10 @@ var wrappertests = []struct {
i int
}{
{"SearchInts", SearchInts(data, 11), 8},
- {"SearchFloats", SearchFloats(fdata, 2.1), 4},
+ {"SearchFloat64s", SearchFloat64s(fdata, 2.1), 4},
{"SearchStrings", SearchStrings(sdata, ""), 0},
{"IntArray.Search", IntArray(data).Search(0), 2},
- {"FloatArray.Search", FloatArray(fdata).Search(2.0), 3},
+ {"Float64Array.Search", Float64Array(fdata).Search(2.0), 3},
{"StringArray.Search", StringArray(sdata).Search("x"), 3},
}
diff --git a/src/pkg/sort/sort.go b/src/pkg/sort/sort.go
index 02e647fca..c7945d21b 100644
--- a/src/pkg/sort/sort.go
+++ b/src/pkg/sort/sort.go
@@ -166,15 +166,15 @@ func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p IntArray) Sort() { Sort(p) }
-// FloatArray attaches the methods of Interface to []float, sorting in increasing order.
-type FloatArray []float
+// Float64Array attaches the methods of Interface to []float64, sorting in increasing order.
+type Float64Array []float64
-func (p FloatArray) Len() int { return len(p) }
-func (p FloatArray) Less(i, j int) bool { return p[i] < p[j] }
-func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+func (p Float64Array) Len() int { return len(p) }
+func (p Float64Array) Less(i, j int) bool { return p[i] < p[j] }
+func (p Float64Array) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Sort is a convenience method.
-func (p FloatArray) Sort() { Sort(p) }
+func (p Float64Array) Sort() { Sort(p) }
// StringArray attaches the methods of Interface to []string, sorting in increasing order.
@@ -192,15 +192,15 @@ func (p StringArray) Sort() { Sort(p) }
// SortInts sorts an array of ints in increasing order.
func SortInts(a []int) { Sort(IntArray(a)) }
-// SortFloats sorts an array of floats in increasing order.
-func SortFloats(a []float) { Sort(FloatArray(a)) }
+// SortFloat64s sorts an array of float64s in increasing order.
+func SortFloat64s(a []float64) { Sort(Float64Array(a)) }
// SortStrings sorts an array of strings in increasing order.
func SortStrings(a []string) { Sort(StringArray(a)) }
// IntsAreSorted tests whether an array of ints is sorted in increasing order.
func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)) }
-// FloatsAreSorted tests whether an array of floats is sorted in increasing order.
-func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)) }
+// Float64sAreSorted tests whether an array of float64s is sorted in increasing order.
+func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Array(a)) }
// StringsAreSorted tests whether an array of strings is sorted in increasing order.
func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)) }
diff --git a/src/pkg/sort/sort_test.go b/src/pkg/sort/sort_test.go
index 2085a67c8..1bea8f032 100644
--- a/src/pkg/sort/sort_test.go
+++ b/src/pkg/sort/sort_test.go
@@ -13,7 +13,7 @@ import (
var ints = [...]int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586}
-var floats = [...]float{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8}
+var float64s = [...]float64{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8}
var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}
func TestSortIntArray(t *testing.T) {
@@ -26,12 +26,12 @@ func TestSortIntArray(t *testing.T) {
}
}
-func TestSortFloatArray(t *testing.T) {
- data := floats
- a := FloatArray(data[0:])
+func TestSortFloat64Array(t *testing.T) {
+ data := float64s
+ a := Float64Array(data[0:])
Sort(a)
if !IsSorted(a) {
- t.Errorf("sorted %v", floats)
+ t.Errorf("sorted %v", float64s)
t.Errorf(" got %v", data)
}
}
@@ -55,11 +55,11 @@ func TestSortInts(t *testing.T) {
}
}
-func TestSortFloats(t *testing.T) {
- data := floats
- SortFloats(data[0:])
- if !FloatsAreSorted(data[0:]) {
- t.Errorf("sorted %v", floats)
+func TestSortFloat64s(t *testing.T) {
+ data := float64s
+ SortFloat64s(data[0:])
+ if !Float64sAreSorted(data[0:]) {
+ t.Errorf("sorted %v", float64s)
t.Errorf(" got %v", data)
}
}