Documentation ¶
Overview ¶
Package sortutil provides utilities supplementing the standard 'sort' package.
Index ¶
- func Dedupe(data sort.Interface) (n int)
- func SearchBytes(a []byte, x byte) int
- func SearchFloat32s(a []float32, x float32) int
- func SearchInt16s(a []int16, x int16) int
- func SearchInt32s(a []int32, x int32) int
- func SearchInt64s(a []int64, x int64) int
- func SearchInt8s(a []int8, x int8) int
- func SearchRunes(a []rune, x rune) int
- func SearchUint16s(a []uint16, x uint16) int
- func SearchUint32s(a []uint32, x uint32) int
- func SearchUint64s(a []uint64, x uint64) int
- func SearchUints(a []uint, x uint) int
- type ByteSlice
- type Float32Slice
- type Int16Slice
- type Int32Slice
- type Int64Slice
- type Int8Slice
- type RuneSlice
- type Uint16Slice
- type Uint32Slice
- type Uint64Slice
- type UintSlice
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dedupe ¶
Dedupe returns n, the number of distinct elements in data. The resulting elements are sorted in elements [0, n) or data[:n] for a slice.
Example ¶
a := []int{4, 1, 2, 1, 3, 4, 2} fmt.Println(a[:Dedupe(sort.IntSlice(a))]) b := []string{"foo", "bar", "baz", "bar", "foo", "qux", "qux"} fmt.Println(b[:Dedupe(sort.StringSlice(b))])
Output: [1 2 3 4] [bar baz foo qux]
func SearchBytes ¶
SearchBytes searches for x in a sorted slice of bytes and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchFloat32s ¶
SearchFloat32s searches for x in a sorted slice of float32 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchInt16s ¶
SearchInt16s searches for x in a sorted slice of int16 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchInt32s ¶
SearchInt32s searches for x in a sorted slice of int32 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchInt64s ¶
SearchInt64s searches for x in a sorted slice of int64 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchInt8s ¶
SearchInt8s searches for x in a sorted slice of int8 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchRunes ¶
SearchRunes searches for x in a sorted slice of uint64 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchUint16s ¶
SearchUint16s searches for x in a sorted slice of uint16 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchUint32s ¶
SearchUint32s searches for x in a sorted slice of uint32 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchUint64s ¶
SearchUint64s searches for x in a sorted slice of uint64 and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
func SearchUints ¶
SearchUints searches for x in a sorted slice of uints and returns the index as specified by sort.Search. The slice must be sorted in ascending order.
Types ¶
type ByteSlice ¶
type ByteSlice []byte
ByteSlice attaches the methods of sort.Interface to []byte, sorting in increasing order.
type Float32Slice ¶
type Float32Slice []float32
Float32Slice attaches the methods of sort.Interface to []float32, sorting in increasing order.
func (Float32Slice) Len ¶
func (s Float32Slice) Len() int
func (Float32Slice) Less ¶
func (s Float32Slice) Less(i, j int) bool
func (Float32Slice) Swap ¶
func (s Float32Slice) Swap(i, j int)
type Int16Slice ¶
type Int16Slice []int16
Int16Slice attaches the methods of sort.Interface to []int16, sorting in increasing order.
func (Int16Slice) Len ¶
func (s Int16Slice) Len() int
func (Int16Slice) Less ¶
func (s Int16Slice) Less(i, j int) bool
func (Int16Slice) Swap ¶
func (s Int16Slice) Swap(i, j int)
type Int32Slice ¶
type Int32Slice []int32
Int32Slice attaches the methods of sort.Interface to []int32, sorting in increasing order.
func (Int32Slice) Len ¶
func (s Int32Slice) Len() int
func (Int32Slice) Less ¶
func (s Int32Slice) Less(i, j int) bool
func (Int32Slice) Swap ¶
func (s Int32Slice) Swap(i, j int)
type Int64Slice ¶
type Int64Slice []int64
Int64Slice attaches the methods of sort.Interface to []int64, sorting in increasing order.
func (Int64Slice) Len ¶
func (s Int64Slice) Len() int
func (Int64Slice) Less ¶
func (s Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (s Int64Slice) Swap(i, j int)
type Int8Slice ¶
type Int8Slice []int8
Int8Slice attaches the methods of sort.Interface to []int8, sorting in increasing order.
type RuneSlice ¶
type RuneSlice []rune
RuneSlice attaches the methods of sort.Interface to []rune, sorting in increasing order.
type Uint16Slice ¶
type Uint16Slice []uint16
Uint16Slice attaches the methods of sort.Interface to []uint16, sorting in increasing order.
func (Uint16Slice) Len ¶
func (s Uint16Slice) Len() int
func (Uint16Slice) Less ¶
func (s Uint16Slice) Less(i, j int) bool
func (Uint16Slice) Swap ¶
func (s Uint16Slice) Swap(i, j int)
type Uint32Slice ¶
type Uint32Slice []uint32
Uint32Slice attaches the methods of sort.Interface to []uint32, sorting in increasing order.
func (Uint32Slice) Len ¶
func (s Uint32Slice) Len() int
func (Uint32Slice) Less ¶
func (s Uint32Slice) Less(i, j int) bool
func (Uint32Slice) Swap ¶
func (s Uint32Slice) Swap(i, j int)
type Uint64Slice ¶
type Uint64Slice []uint64
Uint64Slice attaches the methods of sort.Interface to []uint64, sorting in increasing order.
func (Uint64Slice) Len ¶
func (s Uint64Slice) Len() int
func (Uint64Slice) Less ¶
func (s Uint64Slice) Less(i, j int) bool
func (Uint64Slice) Swap ¶
func (s Uint64Slice) Swap(i, j int)