Package sort
import "sort"
The sort package provides primitives for sorting arrays and user-defined collections.
Package files
sort.gofunc FloatsAreSorted
func FloatsAreSorted(a []float) bool
FloatsAreSorted tests whether an array of floats is sorted in increasing order.
func IntsAreSorted
func IntsAreSorted(a []int) bool
IntsAreSorted tests whether an array of ints is sorted in increasing order.
func IsSorted
func IsSorted(data Interface) bool
func Sort
func Sort(data Interface)
func SortFloats
func SortFloats(a []float)
SortFloats sorts an array of floats in increasing order.
func SortInts
func SortInts(a []int)
SortInts sorts an array of ints in increasing order.
func SortStrings
func SortStrings(a []string)
SortStrings sorts an array of strings in increasing order.
func StringsAreSorted
func StringsAreSorted(a []string) bool
StringsAreSorted tests whether an array of strings is sorted in increasing order.
type FloatArray
FloatArray attaches the methods of Interface to []float, sorting in increasing order.
type FloatArray []float
func (FloatArray) Len
func (p FloatArray) Len() int
func (FloatArray) Less
func (p FloatArray) Less(i, j int) bool
func (FloatArray) Sort
func (p FloatArray) Sort()
Sort is a convenience method.
func (FloatArray) Swap
func (p FloatArray) Swap(i, j int)
type IntArray
IntArray attaches the methods of Interface to []int, sorting in increasing order.
type IntArray []int
func (IntArray) Len
func (p IntArray) Len() int
func (IntArray) Less
func (p IntArray) Less(i, j int) bool
func (IntArray) Sort
func (p IntArray) Sort()
Sort is a convenience method.
func (IntArray) Swap
func (p IntArray) Swap(i, j int)
type Interface
A type, typically a collection, that satisfies sort.Interface can be sorted by the routines in this package. The methods require that the elements of the collection be enumerated by an integer index.
type Interface interface {
// Len is the number of elements in the collection.
Len() int
// Less returns whether the element with index i should sort
// before the element with index j.
Less(i, j int) bool
// Swap swaps the elements with indexes i and j.
Swap(i, j int)
}
type StringArray
StringArray attaches the methods of Interface to []string, sorting in increasing order.
type StringArray []string
func (StringArray) Len
func (p StringArray) Len() int
func (StringArray) Less
func (p StringArray) Less(i, j int) bool
func (StringArray) Sort
func (p StringArray) Sort()
Sort is a convenience method.
func (StringArray) Swap
func (p StringArray) Swap(i, j int)
