mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-10-26 13:17:39 +00:00
Use the Hypher interface in a lot of places
This commit is contained in:
committed by
Timur Ismagilov
parent
ff10d577d2
commit
927ac4f1da
22
tree/tree.go
22
tree/tree.go
@@ -18,25 +18,25 @@ func findSiblings(hyphaName string) []*sibling {
|
||||
}
|
||||
var (
|
||||
siblingsMap = make(map[string]bool)
|
||||
siblingCheck = func(h *hyphae.Hypha) hyphae.CheckResult {
|
||||
siblingCheck = func(h hyphae.Hypher) hyphae.CheckResult {
|
||||
switch {
|
||||
case h.Name == hyphaName, // Hypha is no sibling of itself
|
||||
h.Name == parentHyphaName: // Parent hypha is no sibling of its child
|
||||
case h.CanonicalName() == hyphaName, // Hypha is no sibling of itself
|
||||
h.CanonicalName() == parentHyphaName: // Parent hypha is no sibling of its child
|
||||
return hyphae.CheckContinue
|
||||
}
|
||||
if (parentHyphaName != "" && strings.HasPrefix(h.Name, parentHyphaName+"/")) ||
|
||||
if (parentHyphaName != "" && strings.HasPrefix(h.CanonicalName(), parentHyphaName+"/")) ||
|
||||
(parentHyphaName == "") {
|
||||
var (
|
||||
rawSubPath = strings.TrimPrefix(h.Name, parentHyphaName)[1:]
|
||||
rawSubPath = strings.TrimPrefix(h.CanonicalName(), parentHyphaName)[1:]
|
||||
slashIdx = strings.IndexRune(rawSubPath, '/')
|
||||
)
|
||||
if slashIdx > -1 {
|
||||
var sibPath = h.Name[:slashIdx+len(parentHyphaName)+1]
|
||||
var sibPath = h.CanonicalName()[:slashIdx+len(parentHyphaName)+1]
|
||||
if _, exists := siblingsMap[sibPath]; !exists {
|
||||
siblingsMap[sibPath] = false
|
||||
}
|
||||
} else { // it is a straight sibling
|
||||
siblingsMap[h.Name] = true
|
||||
siblingsMap[h.CanonicalName()] = true
|
||||
}
|
||||
}
|
||||
return hyphae.CheckContinue
|
||||
@@ -63,12 +63,12 @@ func findSiblings(hyphaName string) []*sibling {
|
||||
|
||||
func countSubhyphae(siblings []*sibling) {
|
||||
var (
|
||||
subhyphaCheck = func(h *hyphae.Hypha) hyphae.CheckResult {
|
||||
subhyphaCheck = func(h hyphae.Hypher) hyphae.CheckResult {
|
||||
for _, s := range siblings {
|
||||
if path.Dir(h.Name) == s.name {
|
||||
if path.Dir(h.CanonicalName()) == s.name {
|
||||
s.directSubhyphaeCount++
|
||||
return hyphae.CheckContinue
|
||||
} else if strings.HasPrefix(h.Name, s.name+"/") {
|
||||
} else if strings.HasPrefix(h.CanonicalName(), s.name+"/") {
|
||||
s.indirectSubhyphaeCount++
|
||||
return hyphae.CheckContinue
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func figureOutChildren(hyphaName string) child {
|
||||
)
|
||||
|
||||
for desc := range hyphae.YieldExistingHyphae() {
|
||||
var descName = desc.Name
|
||||
var descName = desc.CanonicalName()
|
||||
if strings.HasPrefix(descName, descPrefix) {
|
||||
var subPath = strings.TrimPrefix(descName, descPrefix)
|
||||
addHyphaToChild(descName, subPath, &child)
|
||||
|
||||
Reference in New Issue
Block a user