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