// ConstructTree takes a map of host -> public keys and a branching factor // so it can constructs a regular tree. THe returned tree is the root // it is constructed bfs style func constructTree(hosts, pubs []string, bf int) *graphs.Tree { var root *graphs.Tree = new(graphs.Tree) root.Name = hosts[0] root.PubKey = pubs[0] var index int = 1 bfs := make([]*graphs.Tree, 1) bfs[0] = root for len(bfs) > 0 && index < len(hosts) { t := bfs[0] t.Children = make([]*graphs.Tree, 0) lbf := 0 // create space for enough children // init them for lbf < bf && index < len(hosts) { child := new(graphs.Tree) child.Name = hosts[index] child.PubKey = pubs[index] // append the children to the list of trees to visit bfs = append(bfs, child) t.Children = append(t.Children, child) index += 1 lbf += 1 } bfs = bfs[1:] } return root }