std/sort
import "github.com/eugenioenko/goalchemy/std/sort"Package sort sorts collections through the Len, Less, and Swap methods. Sort is stable here; Go only guarantees that Stable is.
func Ints(x []int)Ints sorts x in increasing order.
IntsAreSorted
Section titled “IntsAreSorted”func IntsAreSorted(x []int) boolIntsAreSorted reports whether x is sorted in increasing order.
IsSorted
Section titled “IsSorted”func IsSorted(data Interface) boolIsSorted reports whether data is sorted.
Search
Section titled “Search”func Search(n int, f func(int) bool) intSearch returns the smallest index i in [0, n) for which f(i) is true, assuming f is false then true over the range, or n if there is none.
SearchInts
Section titled “SearchInts”func SearchInts(a []int, x int) intSearchInts returns the index at which x is or would be inserted in the sorted slice a.
SearchStrings
Section titled “SearchStrings”func SearchStrings(a []string, x string) intSearchStrings returns the index at which x is or would be inserted in the sorted slice a.
func Sort(data Interface)Sort sorts data in ascending order as determined by Less.
Stable
Section titled “Stable”func Stable(data Interface)Stable sorts data keeping the original order of equal elements.
Strings
Section titled “Strings”func Strings(x []string)Strings sorts x in increasing byte order.
StringsAreSorted
Section titled “StringsAreSorted”func StringsAreSorted(x []string) boolStringsAreSorted reports whether x is sorted in increasing order.
type IntSlice
Section titled “type IntSlice”type IntSlice []intIntSlice attaches the methods of Interface to []int.
IntSlice.Len
Section titled “IntSlice.Len”func (x IntSlice) Len() intIntSlice.Less
Section titled “IntSlice.Less”func (x IntSlice) Less(i, j int) boolIntSlice.Swap
Section titled “IntSlice.Swap”func (x IntSlice) Swap(i, j int)type Interface
Section titled “type Interface”type Interface interface { Len() int Less(i, j int) bool Swap(i, j int)}Interface is a collection that can be sorted by index.
Reverse
Section titled “Reverse”func Reverse(data Interface) InterfaceReverse returns data with the opposite order.
type StringSlice
Section titled “type StringSlice”type StringSlice []stringStringSlice attaches the methods of Interface to []string.
StringSlice.Len
Section titled “StringSlice.Len”func (x StringSlice) Len() intStringSlice.Less
Section titled “StringSlice.Less”func (x StringSlice) Less(i, j int) boolStringSlice.Swap
Section titled “StringSlice.Swap”func (x StringSlice) Swap(i, j int)