github.com/mephux/docker@v1.6.0-rc5/pkg/graphdb/sort.go (about) 1 package graphdb 2 3 import "sort" 4 5 type pathSorter struct { 6 paths []string 7 by func(i, j string) bool 8 } 9 10 func sortByDepth(paths []string) { 11 s := &pathSorter{paths, func(i, j string) bool { 12 return PathDepth(i) > PathDepth(j) 13 }} 14 sort.Sort(s) 15 } 16 17 func (s *pathSorter) Len() int { 18 return len(s.paths) 19 } 20 21 func (s *pathSorter) Swap(i, j int) { 22 s.paths[i], s.paths[j] = s.paths[j], s.paths[i] 23 } 24 25 func (s *pathSorter) Less(i, j int) bool { 26 return s.by(s.paths[i], s.paths[j]) 27 }