mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-12-06 16:38:08 +00:00
Move hyphae.Iteration to a separate package
This commit is contained in:
19
tree/tree.go
19
tree/tree.go
@@ -2,6 +2,7 @@ package tree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycorrhiza/hyphae/iteration"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -18,11 +19,11 @@ func findSiblings(hyphaName string) []*sibling {
|
||||
}
|
||||
var (
|
||||
siblingsMap = make(map[string]bool)
|
||||
siblingCheck = func(h hyphae.Hypha) hyphae.CheckResult {
|
||||
siblingCheck = func(h hyphae.Hypha) iteration.CheckResult {
|
||||
switch {
|
||||
case h.CanonicalName() == hyphaName, // NonEmptyHypha is no sibling of itself
|
||||
h.CanonicalName() == parentHyphaName: // Parent hypha is no sibling of its child
|
||||
return hyphae.CheckContinue
|
||||
return iteration.CheckContinue
|
||||
}
|
||||
if (parentHyphaName != "" && strings.HasPrefix(h.CanonicalName(), parentHyphaName+"/")) ||
|
||||
(parentHyphaName == "") {
|
||||
@@ -39,10 +40,10 @@ func findSiblings(hyphaName string) []*sibling {
|
||||
siblingsMap[h.CanonicalName()] = true
|
||||
}
|
||||
}
|
||||
return hyphae.CheckContinue
|
||||
return iteration.CheckContinue
|
||||
}
|
||||
|
||||
i7n = hyphae.NewIteration()
|
||||
i7n = iteration.NewIteration()
|
||||
)
|
||||
siblingsMap[hyphaName] = true
|
||||
|
||||
@@ -63,19 +64,19 @@ func findSiblings(hyphaName string) []*sibling {
|
||||
|
||||
func countSubhyphae(siblings []*sibling) {
|
||||
var (
|
||||
subhyphaCheck = func(h hyphae.Hypha) hyphae.CheckResult {
|
||||
subhyphaCheck = func(h hyphae.Hypha) iteration.CheckResult {
|
||||
for _, s := range siblings {
|
||||
if path.Dir(h.CanonicalName()) == s.name {
|
||||
s.directSubhyphaeCount++
|
||||
return hyphae.CheckContinue
|
||||
return iteration.CheckContinue
|
||||
} else if strings.HasPrefix(h.CanonicalName(), s.name+"/") {
|
||||
s.indirectSubhyphaeCount++
|
||||
return hyphae.CheckContinue
|
||||
return iteration.CheckContinue
|
||||
}
|
||||
}
|
||||
return hyphae.CheckContinue
|
||||
return iteration.CheckContinue
|
||||
}
|
||||
i7n = hyphae.NewIteration()
|
||||
i7n = iteration.NewIteration()
|
||||
)
|
||||
i7n.AddCheck(subhyphaCheck)
|
||||
i7n.Ignite()
|
||||
|
||||
Reference in New Issue
Block a user