2020-10-21 01:54:58 +00:00
|
|
|
package treeops
|
|
|
|
|
2020-10-21 02:54:51 +00:00
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
[Mike: cat, Bob: dog]
|
|
|
|
[Thing: rabbit, peter: sam]
|
|
|
|
|
|
|
|
==> cross multiply
|
|
|
|
|
|
|
|
{Mike: cat, Thing: rabbit}
|
|
|
|
{Mike: cat, peter: sam}
|
|
|
|
...
|
|
|
|
*/
|
2020-10-21 01:54:58 +00:00
|
|
|
|
|
|
|
func CollectObjectOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) {
|
|
|
|
log.Debugf("-- collectObjectOperation")
|
2020-10-21 02:54:51 +00:00
|
|
|
return collect(d, list.New(), matchMap)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func collect(d *dataTreeNavigator, aggregate *list.List, remainingMatches *list.List) (*list.List, error) {
|
|
|
|
if remainingMatches.Len() == 0 {
|
|
|
|
return aggregate, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
candidate := remainingMatches.Remove(remainingMatches.Front()).(*CandidateNode)
|
|
|
|
splatted, err := Splat(d, nodeToMap(candidate))
|
2020-10-28 02:00:26 +00:00
|
|
|
|
|
|
|
for splatEl := splatted.Front(); splatEl != nil; splatEl = splatEl.Next() {
|
|
|
|
splatEl.Value.(*CandidateNode).Path = nil
|
|
|
|
}
|
|
|
|
|
2020-10-21 02:54:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if aggregate.Len() == 0 {
|
|
|
|
return collect(d, splatted, remainingMatches)
|
|
|
|
}
|
|
|
|
|
|
|
|
newAgg := list.New()
|
|
|
|
|
|
|
|
for el := aggregate.Front(); el != nil; el = el.Next() {
|
|
|
|
aggCandidate := el.Value.(*CandidateNode)
|
|
|
|
for splatEl := splatted.Front(); splatEl != nil; splatEl = splatEl.Next() {
|
|
|
|
splatCandidate := splatEl.Value.(*CandidateNode)
|
|
|
|
newCandidate := aggCandidate.Copy()
|
|
|
|
newCandidate.Path = nil
|
|
|
|
|
2020-10-28 02:00:26 +00:00
|
|
|
newCandidate, err := multiply(d, newCandidate, splatCandidate)
|
2020-10-21 02:54:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
newAgg.PushBack(newCandidate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return collect(d, newAgg, remainingMatches)
|
|
|
|
|
2020-10-21 01:54:58 +00:00
|
|
|
}
|