Examples using... "sort"

Recent
ReportMetric adds "n unit" to the reported benchmark results. If the metric is per-iteration, the caller should divide by b.N, and by convention units should end in "/op". ReportMetric overrides any previously reported value for the same unit. ReportMetric panics if unit is the empty string or if un...
Package sort provides primitives for sorting slices and user-defined collections.
ExampleMultiKeys demonstrates a technique for sorting a struct type using different sets of multiple fields in the comparison. We chain together "Less" functions, each of which compares a single field.
ExampleSortKeys demonstrates a technique for sorting a struct type using programmable sort criteria.
Package sort provides primitives for sorting slices and user-defined collections.
Strings sorts a slice of strings in increasing order.
This example demonstrates searching a list sorted in descending order. The approach is the same as searching a list in ascending order, but with the condition inverted.
This example demonstrates searching a list sorted in ascending order.
Reverse returns the reverse order for data.
IntsAreSorted tests whether a slice of ints is sorted in increasing order.
Ints sorts a slice of ints in increasing order.
Float64sAreSorted tests whether a slice of float64s is sorted in increasing order (not-a-number values are treated as less than other values).
Float64s sorts a slice of float64s in increasing order (not-a-number values are treated as less than other values).
ExampleInfo prints various facts recorded by the type checker in a types.Info struct: definitions of and references to each named object, and the type, value, and mode of every expression in the package.
Compare returns the result of the comparison x op y. The comparison must be defined for the operands. If one of the operands is Unknown, the result is false.
Compare returns an integer comparing two byte slices lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. A nil argument is equivalent to an empty slice.
Sometimes we’ll want to sort a collection by something other than its natural order. For example, suppose we wanted to sort strings by their length instead of alphabetically. Here’s an example of custom sorts in Go.
Go’s sort package implements sorting for builtins and user-defined types.