sort_linux.go 478 B

123456789101112131415161718192021222324252627
  1. package graphdb
  2. import "sort"
  3. type pathSorter struct {
  4. paths []string
  5. by func(i, j string) bool
  6. }
  7. func sortByDepth(paths []string) {
  8. s := &pathSorter{paths, func(i, j string) bool {
  9. return PathDepth(i) > PathDepth(j)
  10. }}
  11. sort.Sort(s)
  12. }
  13. func (s *pathSorter) Len() int {
  14. return len(s.paths)
  15. }
  16. func (s *pathSorter) Swap(i, j int) {
  17. s.paths[i], s.paths[j] = s.paths[j], s.paths[i]
  18. }
  19. func (s *pathSorter) Less(i, j int) bool {
  20. return s.by(s.paths[i], s.paths[j])
  21. }