forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils_sort.go
34 lines (26 loc) · 955 Bytes
/
utils_sort.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
package utils
import (
"sort"
"github.com/rexray/rexray/libstorage/api/types"
)
// ByVolumeID implements sort.Interface for []*types.Volume based on the ID
// field.
type ByVolumeID []*types.Volume
func (a ByVolumeID) Len() int { return len(a) }
func (a ByVolumeID) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByVolumeID) Less(i, j int) bool { return a[i].ID < a[j].ID }
// SortVolumeByID sorts the volumes by their IDs.
func SortVolumeByID(volumes []*types.Volume) []*types.Volume {
sort.Sort(ByVolumeID(volumes))
return volumes
}
// ByString implements sort.Interface for []string.
type ByString []string
func (a ByString) Len() int { return len(a) }
func (a ByString) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByString) Less(i, j int) bool { return a[i] < a[j] }
// SortByString sorts the strings.
func SortByString(strings []string) []string {
sort.Sort(ByString(strings))
return strings
}