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

61 lines
1.0 KiB
Go

package tea
import (
"io"
)
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}
}
func (s Selection) countXNodes() int {
total := 0
for _, child := range s.nodes {
total += len(child.xnodes)
}
return total
}
func (s Selection) writeDOT(w io.Writer) {
}