forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorter.go
46 lines (37 loc) · 1.34 KB
/
sorter.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
package api
import (
"github.com/docker/engine-api/types"
"github.com/docker/swarm/cluster"
)
// ContainerSorter implements the Sort interface to sort Docker containers.
// It is not guaranteed to be a stable sort.
type ContainerSorter []*cluster.Container
// Len returns the number of containers to be sorted.
func (s ContainerSorter) Len() int {
return len(s)
}
// Swap exchanges the container elements with indices i and j.
func (s ContainerSorter) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Less reports whether the container with index i should sort before the container with index j.
// Containers are sorted chronologically by when they were created.
func (s ContainerSorter) Less(i, j int) bool {
return s[i].Info.Created < s[j].Info.Created
}
// ImageSorter implements the Sort interface to sort Docker Images.
// It is not guaranteed to be a stable sort.
type ImageSorter []types.Image
// Len returns the number of images to be sorted.
func (s ImageSorter) Len() int {
return len(s)
}
// Swap exchanges the container elements with indices i and j.
func (s ImageSorter) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Less reports whether the Image with index i should sort before the Image with index j.
// Images are sorted chronologically by when they were created.
func (s ImageSorter) Less(i, j int) bool {
return s[i].Created < s[j].Created
}