Skip to content

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.

func IntsAreSorted(x []int) bool

IntsAreSorted reports whether x is sorted in increasing order.

func IsSorted(data Interface) bool

IsSorted reports whether data is sorted.

func Search(n int, f func(int) bool) int

Search 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.

func SearchInts(a []int, x int) int

SearchInts returns the index at which x is or would be inserted in the sorted slice a.

func SearchStrings(a []string, x string) int

SearchStrings 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.

func Stable(data Interface)

Stable sorts data keeping the original order of equal elements.

func Strings(x []string)

Strings sorts x in increasing byte order.

func StringsAreSorted(x []string) bool

StringsAreSorted reports whether x is sorted in increasing order.

type IntSlice []int

IntSlice attaches the methods of Interface to []int.

func (x IntSlice) Len() int
func (x IntSlice) Less(i, j int) bool
func (x IntSlice) Swap(i, j int)
type Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
}

Interface is a collection that can be sorted by index.

func Reverse(data Interface) Interface

Reverse returns data with the opposite order.

type StringSlice []string

StringSlice attaches the methods of Interface to []string.

func (x StringSlice) Len() int
func (x StringSlice) Less(i, j int) bool
func (x StringSlice) Swap(i, j int)