diff options
Diffstat (limited to 'runtime/sorter.go')
-rw-r--r-- | runtime/sorter.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/runtime/sorter.go b/runtime/sorter.go new file mode 100644 index 0000000000..c5af772dae --- /dev/null +++ b/runtime/sorter.go @@ -0,0 +1,25 @@ +package runtime + +import "sort" + +type containerSorter struct { + containers []*Container + by func(i, j *Container) bool +} + +func (s *containerSorter) Len() int { + return len(s.containers) +} + +func (s *containerSorter) Swap(i, j int) { + s.containers[i], s.containers[j] = s.containers[j], s.containers[i] +} + +func (s *containerSorter) Less(i, j int) bool { + return s.by(s.containers[i], s.containers[j]) +} + +func sortContainers(containers []*Container, predicate func(i, j *Container) bool) { + s := &containerSorter{containers, predicate} + sort.Sort(s) +} |