sortext

package
v2.0.0-...-8dcd6a7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2015 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package sortext contains extensions to the base Go sort package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigInts

func BigInts(a []*big.Int)

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

func BigIntsAreSorted(a []*big.Int) bool

BigIntsAreSorted tests whether a slice of *big.Ints is sorted in increasing order.

func BigRats

func BigRats(a []*big.Rat)

BigRats sorts a slice of *big.Rats in increasing order.

func BigRatsAreSorted

func BigRatsAreSorted(a []*big.Rat) bool

BigRatsAreSorted tests whether a slice of *big.Rats is sorted in increasing order.

func SearchBigInts

func SearchBigInts(a []*big.Int, x *big.Int) int

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

func SearchBigRats(a []*big.Rat, x *big.Rat) int

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

func Unique(data sort.Interface) int

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

type BigIntSlice []*big.Int

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) Sort

func (b BigIntSlice) Sort()

Sort is a convenience method.

func (BigIntSlice) Swap

func (b BigIntSlice) Swap(i, j int)

type BigRatSlice

type BigRatSlice []*big.Rat

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) Sort

func (b BigRatSlice) Sort()

Sort is a convenience method.

func (BigRatSlice) Swap

func (b BigRatSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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