7 type RootSorter struct {
13 func NewRootSorter(serviceRoots map[string]string, hash string) (*RootSorter) {
15 rs.root = make([]string, len(serviceRoots))
16 rs.weight = make([]string, len(serviceRoots))
17 rs.order = make([]int, len(serviceRoots))
19 for uuid, root := range serviceRoots {
21 rs.weight[i] = rs.getWeight(hash, uuid)
29 func (rs RootSorter) getWeight(hash string, uuid string) (string) {
31 return Md5String(hash + uuid[12:])
33 // Only useful for testing, a set of one service root, etc.
34 return Md5String(hash + uuid)
38 func (rs RootSorter) GetSortedRoots() ([]string) {
39 sorted := make([]string, len(rs.order))
40 for i := range rs.order {
41 sorted[i] = rs.root[rs.order[i]]
46 // Less is really More here: the heaviest root will be at the front of the list.
47 func (rs RootSorter) Less(i, j int) bool {
48 return rs.weight[rs.order[j]] < rs.weight[rs.order[i]]
51 func (rs RootSorter) Len() int {
55 func (rs RootSorter) Swap(i, j int) {
56 sort.IntSlice(rs.order).Swap(i, j)