github.com/pbberlin/tools@v0.0.0-20160910141205-7aa5421c2169/appengine/backend/backend3_sort.go (about) 1 package backend 2 3 type Order struct { 4 IdxSrc int // index to the base slice 5 ByI int // the base for sorting by int 6 ByS string // the base for sorting by string 7 } 8 type ByInt []Order 9 type ByStr []Order 10 11 // We could condense the .Len() and .Swap() methods. 12 func (s ByInt) Len() int { return len(s) } 13 func (s ByInt) Less(i, j int) bool { return s[i].ByI < s[j].ByI } 14 func (s ByInt) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 15 16 func (s ByStr) Len() int { return len(s) } 17 func (s ByStr) Less(i, j int) bool { return s[i].ByS < s[j].ByS } 18 func (s ByStr) Swap(i, j int) { s[i], s[j] = s[j], s[i] }