Move utility package 'graphdb' to pkg/graphdb
This commit is contained in:
parent
81b755db9b
commit
ced35db5c1
8 changed files with 1130 additions and 0 deletions
27
graphdb/sort.go
Normal file
27
graphdb/sort.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package graphdb
|
||||
|
||||
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 {
|
||||
return PathDepth(i) > PathDepth(j)
|
||||
}}
|
||||
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])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue