forked from twotwotwo/sorts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.go
64 lines (55 loc) · 1.66 KB
/
interfaces.go
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
56
57
58
59
60
61
62
63
64
// 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
}
// Uint128Interface represents a collection that can be sorted by a uint128
// key.
type Uint128Interface interface {
sort.Interface
// Key provides a uint128 key for element i, in the form of 2 uint64s
// containing the high and low bits, respectively.
Key(i int) (uint64, 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--
}
}