Documentation ¶
Overview ¶
Package sortext contains extensions to the base Go sort package.
Index ¶
- func BigInts(a []*big.Int)
- func BigIntsAreSorted(a []*big.Int) bool
- func BigRats(a []*big.Rat)
- func BigRatsAreSorted(a []*big.Rat) bool
- func SearchBigInts(a []*big.Int, x *big.Int) int
- func SearchBigRats(a []*big.Rat, x *big.Rat) int
- func Unique(data sort.Interface) int
- type BigIntSlice
- type BigRatSlice
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BigInts ¶
BigInts sorts a slice of *big.Ints in increasing order.
Example ¶
package main import ( "fmt" "math/big" "gopkg.in/karalabe/cookiejar.v2/exts/sortext" ) func main() { // Define some sample big ints one := big.NewInt(1) two := big.NewInt(2) three := big.NewInt(3) four := big.NewInt(4) five := big.NewInt(5) six := big.NewInt(6) // Sort and print a random slice s := []*big.Int{five, two, six, three, one, four} sortext.BigInts(s) fmt.Println(s) }
Output: [1 2 3 4 5 6]
func BigIntsAreSorted ¶
BigIntsAreSorted tests whether a slice of *big.Ints is sorted in increasing order.
func BigRatsAreSorted ¶
BigRatsAreSorted tests whether a slice of *big.Rats is sorted in increasing order.
func SearchBigInts ¶
SearchBigInts searches for x in a sorted slice of *big.Ints and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.
func SearchBigRats ¶
SearchBigRats searches for x in a sorted slice of *big.Rats and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.
func Unique ¶
Unique gathers the first occurance of each element to the front, returning their number. Data must be sorted in ascending order. The order of the rest is ruined.
Example ¶
package main import ( "fmt" "sort" "gopkg.in/karalabe/cookiejar.v2/exts/sortext" ) func main() { // Create some array of data data := []int{1, 5, 4, 3, 1, 3, 2, 5, 4, 3, 3, 0, 0} // Sort it sort.Ints(data) // Get unique elements and siplay them n := sortext.Unique(sort.IntSlice(data)) fmt.Println("Uniques:", data[:n]) }
Output: Uniques: [0 1 2 3 4 5]
Types ¶
type BigIntSlice ¶
BigIntSlice attaches the methods of Interface to []*big.Int, sorting in increasing order.
func (BigIntSlice) Len ¶
func (b BigIntSlice) Len() int
func (BigIntSlice) Less ¶
func (b BigIntSlice) Less(i, j int) bool
func (BigIntSlice) Search ¶
func (p BigIntSlice) Search(x *big.Int) int
Search returns the result of applying SearchBigInts to the receiver and x.
func (BigIntSlice) Swap ¶
func (b BigIntSlice) Swap(i, j int)
type BigRatSlice ¶
BigRatSlice attaches the methods of Interface to []*big.Rat, sorting in increasing order.
func (BigRatSlice) Len ¶
func (b BigRatSlice) Len() int
func (BigRatSlice) Less ¶
func (b BigRatSlice) Less(i, j int) bool
func (BigRatSlice) Search ¶
func (p BigRatSlice) Search(x *big.Rat) int
Search returns the result of applying SearchBigRats to the receiver and x.
func (BigRatSlice) Swap ¶
func (b BigRatSlice) Swap(i, j int)