Make parent lookup recursive instead of write
This commit is contained in:
10
document.go
10
document.go
@@ -22,6 +22,16 @@ func NewDocumentWithData(data any) *Document {
|
||||
return doc
|
||||
}
|
||||
|
||||
func (d *Document) AllParents() []*Document {
|
||||
ret := append([]*Document{}, d.Parents...)
|
||||
|
||||
for _, parent := range d.Parents {
|
||||
ret = append(ret, parent.AllParents()...)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (d *Document) String() string {
|
||||
return d.ID.String()
|
||||
}
|
||||
|
||||
10
file.go
10
file.go
@@ -101,10 +101,12 @@ func (p *Parser) loadFileAndParents(path string, child *file) ([]*file, error) {
|
||||
}
|
||||
|
||||
func (f *file) setParents() {
|
||||
for iter := f.child; iter != nil; iter = iter.child {
|
||||
for _, doc := range iter.docs {
|
||||
doc.Parents = append(doc.Parents, f.docs...)
|
||||
}
|
||||
if f.child == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, doc := range f.child.docs {
|
||||
doc.Parents = append(doc.Parents, f.docs...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user