compare

package
v0.0.2-0...-db6250e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2020 License: CC0-1.0, CC0-1.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Max

func Max(R TotalOrder, S ...object.Element) (object.Element, error)

Max returns the maximum element in the slice S. The maximum is calculated with respect to the total order R. If S is empty then an error is returned. If R satisfies the interface:

type Maxer interface {
	Max(S ...object.Element) (object.Element, error) // Max returns the
	   maximum element in the slice S. If S is empty then an error is
	   returned.
}

then R's Max method will be called.

func MaxAndIndex

func MaxAndIndex(R TotalOrder, S []object.Element) (object.Element, int, error)

MaxAndIndex returns the maximum element in the slice S, along with the index of the first occurrence of that element in S. The maximum is calculated with respect to the total order R. If S is empty then an error is returned. If R satisfies the interface:

type MaxAndIndexer interface {
	MaxAndIndex(S []object.Element) (object.Element, int, error)
		// MaxAndIndex returns the maximum element in the slice S,
		   along with the index of the first occurrence of that element
		   in S. If S is empty then an error is returned.
}

then R's MaxAndIndex method will be called.

func MaxOfPair

func MaxOfPair(R TotalOrder, x object.Element, y object.Element) (object.Element, error)

MaxOfPair returns the maximum element of x and y. The maximum is calculated with respect to the total order R.

func Min

func Min(R TotalOrder, S ...object.Element) (object.Element, error)

Min returns the minimum element in the slice S. The minimum is calculated with respect to the total order R. If S is empty then an error is returned. If R satisfies the interface:

type Miner interface {
	Min(S ...object.Element) (object.Element, error) // Min returns the
	   minimum element in the slice S. If S is empty then an error is
	   returned.
}

then R's Min method will be called.

func MinAndIndex

func MinAndIndex(R TotalOrder, S []object.Element) (object.Element, int, error)

MinAndIndex returns the minimum element in the slice S, along with the index of the first occurrence of that element in S. The minimum is calculated with respect to the total order R. If S is empty then an error is returned. If R satisfies the interface:

type MinAndIndexer interface {
	MinAndIndex(S []object.Element) (object.Element, int, error)
		// MinAndIndex returns the minimum element in the slice S,
		   along with the index of the first occurrence of that element
		   in S. If S is empty then an error is returned.
}

then R's MinAndIndex method will be called.

func MinOfPair

func MinOfPair(R TotalOrder, x object.Element, y object.Element) (object.Element, error)

MinOfPair returns the minimum element of x and y. The minimum is calculated with respect to the total order R.

func Sort

func Sort(R TotalOrder, S []object.Element) ([]object.Element, error)

Sort non-destructively sorts the given slice of elements using the given TotalOrder. The sorted slice is returned. If R satisfies the interface:

type Sorter interface {
	Sort(S []object.Element) ([]object.Element, error) // Sort
	  non-destructively sorts the given slice of elements. The sorted
	  slice is returned.
}

then R's Sort method will be called.

func SortWithFunc

func SortWithFunc(less LessFunc, S []object.Element) ([]object.Element, error)

SortWithFunc non-destructively sorts the given slice of elements using the given function. The sorted slice is returned.

Types

type CmpFunc

type CmpFunc func(x object.Element, y object.Element) (int, error)

CmpFunc should return -1 if x < y, 0 if x == y, and +1 if x > y.

type Cmper

type Cmper interface {
	Cmp(x object.Element, y object.Element) (int, error) // Cmp returns -1 if x < y, 0 if x == y, and +1 if x > y.
}

Cmper is the interface satisfied by the Cmp method.

type LessFunc

type LessFunc func(x object.Element, y object.Element) (bool, error)

LessFunc can be used to sort a slice of elements. It should return true iff x < y. The function must be safe to be called concurrently by multiple go routines.

type TotalOrder

type TotalOrder interface {
	object.Containser
	Cmper
}

TotalOrder is the interface satisfied by a total order.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL