2020-10-18 00:31:36 +00:00
|
|
|
package treeops
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/elliotchance/orderedmap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RecursiveDescentOperator(d *dataTreeNavigator, matchMap *orderedmap.OrderedMap, pathNode *PathTreeNode) (*orderedmap.OrderedMap, error) {
|
|
|
|
var results = orderedmap.NewOrderedMap()
|
|
|
|
|
|
|
|
err := recursiveDecent(d, results, matchMap)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func recursiveDecent(d *dataTreeNavigator, results *orderedmap.OrderedMap, matchMap *orderedmap.OrderedMap) error {
|
2020-10-20 04:33:20 +00:00
|
|
|
splatOperation := &Operation{OperationType: TraversePath, Value: "[]"}
|
|
|
|
splatTreeNode := &PathTreeNode{Operation: splatOperation}
|
2020-10-20 02:53:26 +00:00
|
|
|
|
2020-10-18 00:31:36 +00:00
|
|
|
for el := matchMap.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
results.Set(candidate.GetKey(), candidate)
|
|
|
|
|
2020-10-20 02:53:26 +00:00
|
|
|
children, err := TraversePathOperator(d, nodeToMap(candidate), splatTreeNode)
|
2020-10-18 00:31:36 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = recursiveDecent(d, results, children)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|