156
156
// Convenience types for common cases
158
// IntArray attaches the methods of Interface to []int, sorting in increasing order.
161
func (p IntArray) Len() int { return len(p) }
162
func (p IntArray) Less(i, j int) bool { return p[i] < p[j] }
163
func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
165
// Sort is a convenience method.
166
func (p IntArray) Sort() { Sort(p) }
169
// Float64Array attaches the methods of Interface to []float64, sorting in increasing order.
170
type Float64Array []float64
172
func (p Float64Array) Len() int { return len(p) }
173
func (p Float64Array) Less(i, j int) bool { return p[i] < p[j] }
174
func (p Float64Array) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
176
// Sort is a convenience method.
177
func (p Float64Array) Sort() { Sort(p) }
180
// StringArray attaches the methods of Interface to []string, sorting in increasing order.
181
type StringArray []string
183
func (p StringArray) Len() int { return len(p) }
184
func (p StringArray) Less(i, j int) bool { return p[i] < p[j] }
185
func (p StringArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
187
// Sort is a convenience method.
188
func (p StringArray) Sort() { Sort(p) }
158
// IntSlice attaches the methods of Interface to []int, sorting in increasing order.
161
func (p IntSlice) Len() int { return len(p) }
162
func (p IntSlice) Less(i, j int) bool { return p[i] < p[j] }
163
func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
165
// Sort is a convenience method.
166
func (p IntSlice) Sort() { Sort(p) }
169
// Float64Slice attaches the methods of Interface to []float64, sorting in increasing order.
170
type Float64Slice []float64
172
func (p Float64Slice) Len() int { return len(p) }
173
func (p Float64Slice) Less(i, j int) bool { return p[i] < p[j] }
174
func (p Float64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
176
// Sort is a convenience method.
177
func (p Float64Slice) Sort() { Sort(p) }
180
// StringSlice attaches the methods of Interface to []string, sorting in increasing order.
181
type StringSlice []string
183
func (p StringSlice) Len() int { return len(p) }
184
func (p StringSlice) Less(i, j int) bool { return p[i] < p[j] }
185
func (p StringSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
187
// Sort is a convenience method.
188
func (p StringSlice) Sort() { Sort(p) }
191
191
// Convenience wrappers for common cases
193
// SortInts sorts an array of ints in increasing order.
194
func SortInts(a []int) { Sort(IntArray(a)) }
195
// SortFloat64s sorts an array of float64s in increasing order.
196
func SortFloat64s(a []float64) { Sort(Float64Array(a)) }
197
// SortStrings sorts an array of strings in increasing order.
198
func SortStrings(a []string) { Sort(StringArray(a)) }
201
// IntsAreSorted tests whether an array of ints is sorted in increasing order.
202
func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)) }
203
// Float64sAreSorted tests whether an array of float64s is sorted in increasing order.
204
func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Array(a)) }
205
// StringsAreSorted tests whether an array of strings is sorted in increasing order.
206
func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)) }
193
// Ints sorts a slice of ints in increasing order.
194
func Ints(a []int) { Sort(IntSlice(a)) }
195
// Float64s sorts a slice of float64s in increasing order.
196
func Float64s(a []float64) { Sort(Float64Slice(a)) }
197
// Strings sorts a slice of strings in increasing order.
198
func Strings(a []string) { Sort(StringSlice(a)) }
201
// IntsAreSorted tests whether a slice of ints is sorted in increasing order.
202
func IntsAreSorted(a []int) bool { return IsSorted(IntSlice(a)) }
203
// Float64sAreSorted tests whether a slice of float64s is sorted in increasing order.
204
func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Slice(a)) }
205
// StringsAreSorted tests whether a slice of strings is sorted in increasing order.
206
func StringsAreSorted(a []string) bool { return IsSorted(StringSlice(a)) }