github.com/grzegorz-zur/bm@v0.0.0-20240312214136-6fc133e3e2c0/paths.go (about) 1 package main 2 3 import ( 4 "os" 5 "strings" 6 ) 7 8 // Paths represents list of file paths. 9 type Paths []string 10 11 // Len returns length of paths. 12 func (paths Paths) Len() int { 13 return len(paths) 14 } 15 16 // Less compares elements. 17 func (paths Paths) Less(i, j int) bool { 18 pi := paths[i] 19 pj := paths[j] 20 sep := string(os.PathSeparator) 21 si := strings.Count(pi, sep) 22 sj := strings.Count(pj, sep) 23 if si == sj { 24 return pi < pj 25 } 26 return si < sj 27 } 28 29 // Swap exchanges elements. 30 func (paths Paths) Swap(i, j int) { 31 paths[i], paths[j] = paths[j], paths[i] 32 }