You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tea/selection.go

45 lines
854 B
Go

package tea
func NewSelection(test Test) Selection {
x := xnode{
test: clone(test),
}
l := lnode{
id: nextNodeID(),
name: parseName(test),
xnodes: []*xnode{&x},
}
x.lnode = &l
return Selection{
nodes: []*lnode{&l},
}
}
// Selection represents a set of nodes in our graph.
type Selection struct {
nodes []*lnode
}
func (s Selection) Child(test Test) Selection {
child := &lnode{id: nextNodeID(), name: parseName(test)}
for _, l := range s.nodes {
l.child(child, test)
}
return Selection{nodes: []*lnode{child}}
}
func (s Selection) And(other Selection) Selection {
included := make(map[int]bool)
out := make([]*lnode, 0, len(s.nodes)+len(other.nodes))
for _, n := range append(s.nodes, other.nodes...) {
if !included[n.id] {
out = append(out, n)
included[n.id] = true
}
}
return Selection{nodes: out}
}