Rename shared packages by day instead of vaguely by purpose.

This commit is contained in:
Anna Rose Wiggins 2018-12-10 01:06:47 -05:00
parent 42cb05ba7f
commit 31f60eca0e
No known key found for this signature in database
GPG key ID: 8D9ACA841015C59A
22 changed files with 49 additions and 50 deletions

View file

@ -1,46 +0,0 @@
package tree
// FindOrder determines the correct order according to these rules:
// 1. A node cannot come before all of its parents have been included.
// 2. At any given time, the lowest-lettered available step must be executed.
func FindOrder(root *Node) []*Node {
seen := map[rune]bool{
0: true,
}
order := []*Node{}
for {
// continuously loop over the tree, retrieving the next usable node.
candidates := findCandidates(root, seen)
if len(candidates) == 0 {
return order
}
sortNodes(candidates)
order = append(order, candidates[0])
seen[candidates[0].Name] = true
}
}
func findCandidates(node *Node, seen map[rune]bool) []*Node {
candidates := []*Node{}
// if we've been seen before, we're clear to recurse
if seen[node.Name] == true {
for _, child := range node.Children {
candidates = append(candidates, findCandidates(child, seen)...)
}
return candidates
}
// add the node, but only if all its parents have been seen
for _, parent := range node.Parents {
if seen[parent.Name] == false {
return candidates
}
}
// We haven't seen this one before, and its parents are seen.
// Return it as a candidate.
return append(candidates, node)
}