func (it *Base) CopyTagsFrom(other_it graph.Iterator) { for _, tag := range other_it.Tags() { it.AddTag(tag) } for k, v := range other_it.FixedTags() { it.AddFixedTag(k, v) } }
// moveTagsTo() gets the tags for all of the src's subiterators and the // src itself, and moves them to dst. func moveTagsTo(dst graph.Iterator, src *And) { tags := src.getSubTags() for _, tag := range dst.Tags() { if _, ok := tags[tag]; ok { delete(tags, tag) } } for k := range tags { dst.AddTag(k) } }
func (qs *queryShape) MakeNode(it graph.Iterator) *Node { n := Node{Id: qs.nodeId} for _, tag := range it.Tags() { n.Tags = append(n.Tags, tag) } for k, _ := range it.FixedTags() { n.Tags = append(n.Tags, k) } switch it.Type() { case graph.And: for _, sub := range it.SubIterators() { qs.nodeId++ newNode := qs.MakeNode(sub) if sub.Type() != graph.Or { qs.StealNode(&n, newNode) } else { qs.AddNode(newNode) qs.AddLink(&Link{n.Id, newNode.Id, 0, 0}) } } case graph.Fixed: n.IsFixed = true for { val, more := it.Next() if !more { break } n.Values = append(n.Values, qs.ts.NameOf(val)) } case graph.HasA: hasa := it.(*HasA) qs.PushHasa(n.Id, hasa.dir) qs.nodeId++ newNode := qs.MakeNode(hasa.primaryIt) qs.AddNode(newNode) qs.RemoveHasa() case graph.Or: for _, sub := range it.SubIterators() { qs.nodeId++ newNode := qs.MakeNode(sub) if sub.Type() == graph.Or { qs.StealNode(&n, newNode) } else { qs.AddNode(newNode) qs.AddLink(&Link{n.Id, newNode.Id, 0, 0}) } } case graph.LinksTo: n.IsLinkNode = true lto := it.(*LinksTo) qs.nodeId++ newNode := qs.MakeNode(lto.primaryIt) hasaID, hasaDir := qs.LastHasa() if (hasaDir == graph.Subject && lto.dir == graph.Object) || (hasaDir == graph.Object && lto.dir == graph.Subject) { qs.AddNode(newNode) if hasaDir == graph.Subject { qs.AddLink(&Link{hasaID, newNode.Id, 0, n.Id}) } else { qs.AddLink(&Link{newNode.Id, hasaID, 0, n.Id}) } } else if lto.primaryIt.Type() == graph.Fixed { qs.StealNode(&n, newNode) } else { qs.AddNode(newNode) } case graph.Optional: // Unsupported, for the moment fallthrough case graph.All: } return &n }