2013-11-15 23:55:45 +00:00
|
|
|
package graphdb
|
2013-10-05 02:25:15 +00:00
|
|
|
|
|
|
|
import "sort"
|
|
|
|
|
|
|
|
type pathSorter struct {
|
|
|
|
paths []string
|
|
|
|
by func(i, j string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortByDepth(paths []string) {
|
|
|
|
s := &pathSorter{paths, func(i, j string) bool {
|
2013-10-24 23:49:28 +00:00
|
|
|
return PathDepth(i) > PathDepth(j)
|
2013-10-05 02:25:15 +00:00
|
|
|
}}
|
|
|
|
sort.Sort(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pathSorter) Len() int {
|
|
|
|
return len(s.paths)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pathSorter) Swap(i, j int) {
|
|
|
|
s.paths[i], s.paths[j] = s.paths[j], s.paths[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pathSorter) Less(i, j int) bool {
|
|
|
|
return s.by(s.paths[i], s.paths[j])
|
|
|
|
}
|