diff options
Diffstat (limited to 'src/pkg/sort/sort.go')
-rw-r--r-- | src/pkg/sort/sort.go | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/pkg/sort/sort.go b/src/pkg/sort/sort.go index 30b1819af..daed61ea8 100644 --- a/src/pkg/sort/sort.go +++ b/src/pkg/sort/sort.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package sort provides primitives for sorting arrays and user-defined +// Package sort provides primitives for sorting slices and user-defined // collections. package sort @@ -82,7 +82,7 @@ func doPivot(data Interface, lo, hi int) (midlo, midhi int) { // data[d <= i < hi] = pivot // // Once b meets c, can swap the "= pivot" sections - // into the middle of the array. + // into the middle of the slice. pivot := lo a, b, c, d := lo+1, lo+1, hi, hi for b < c { @@ -155,52 +155,52 @@ func IsSorted(data Interface) bool { // Convenience types for common cases -// IntArray attaches the methods of Interface to []int, sorting in increasing order. -type IntArray []int +// IntSlice attaches the methods of Interface to []int, sorting in increasing order. +type IntSlice []int -func (p IntArray) Len() int { return len(p) } -func (p IntArray) Less(i, j int) bool { return p[i] < p[j] } -func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p IntSlice) Len() int { return len(p) } +func (p IntSlice) Less(i, j int) bool { return p[i] < p[j] } +func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p IntArray) Sort() { Sort(p) } +func (p IntSlice) Sort() { Sort(p) } -// Float64Array attaches the methods of Interface to []float64, sorting in increasing order. -type Float64Array []float64 +// Float64Slice attaches the methods of Interface to []float64, sorting in increasing order. +type Float64Slice []float64 -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] } +func (p Float64Slice) Len() int { return len(p) } +func (p Float64Slice) Less(i, j int) bool { return p[i] < p[j] } +func (p Float64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p Float64Array) Sort() { Sort(p) } +func (p Float64Slice) Sort() { Sort(p) } -// StringArray attaches the methods of Interface to []string, sorting in increasing order. -type StringArray []string +// StringSlice attaches the methods of Interface to []string, sorting in increasing order. +type StringSlice []string -func (p StringArray) Len() int { return len(p) } -func (p StringArray) Less(i, j int) bool { return p[i] < p[j] } -func (p StringArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p StringSlice) Len() int { return len(p) } +func (p StringSlice) Less(i, j int) bool { return p[i] < p[j] } +func (p StringSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p StringArray) Sort() { Sort(p) } +func (p StringSlice) Sort() { Sort(p) } // Convenience wrappers for common cases -// SortInts sorts an array of ints in increasing order. -func SortInts(a []int) { Sort(IntArray(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)) } +// Ints sorts a slice of ints in increasing order. +func Ints(a []int) { Sort(IntSlice(a)) } +// Float64s sorts a slice of float64s in increasing order. +func Float64s(a []float64) { Sort(Float64Slice(a)) } +// Strings sorts a slice of strings in increasing order. +func Strings(a []string) { Sort(StringSlice(a)) } -// IntsAreSorted tests whether an array of ints is sorted in increasing order. -func IntsAreSorted(a []int) bool { return IsSorted(IntArray(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)) } +// IntsAreSorted tests whether a slice of ints is sorted in increasing order. +func IntsAreSorted(a []int) bool { return IsSorted(IntSlice(a)) } +// Float64sAreSorted tests whether a slice of float64s is sorted in increasing order. +func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Slice(a)) } +// StringsAreSorted tests whether a slice of strings is sorted in increasing order. +func StringsAreSorted(a []string) bool { return IsSorted(StringSlice(a)) } |