1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// Copyright 2009 The Go Authors.
// Copyright 2015 Randall Farmer.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package sorts does parallel radix sorts of data by (u)int64, string, or
// []byte keys, and parallel quicksort. See the sorts/sortutil package for
// shortcuts for common slice types and help sorting floats.
package sorts
import "sort" // for Interface
// Uint64Interface represents a collection that can be sorted by a uint64
// key.
type Uint64Interface interface {
sort.Interface
// Key provides a uint64 key for element i.
Key(i int) uint64
}
// Int64Interface represents a collection that can be sorted by an int64
// key.
type Int64Interface interface {
sort.Interface
// Key provides an int64 key for element i.
Key(i int) int64
}
// StringInterface represents a collection that can be sorted by a string
// key.
type StringInterface interface {
sort.Interface
// Key provides the string key for element i.
Key(i int) string
}
// BytesInterface represents a collection that can be sorted by a []byte
// key.
type BytesInterface interface {
sort.Interface
// Key provides the []byte key for element i.
Key(i int) []byte
}
// Flip reverses the order of items in a sort.Interface.
func Flip(data sort.Interface) {
a, b := 0, data.Len()-1
for b > a {
data.Swap(a, b)
a++
b--
}
}
|