Esempio n. 1
0
// recurse generated the triple by recursing while there are still triples
// left to generate.
func (t *treeGenerator) recurse(parent *node.Node, left *int, currentDepth, maxDepth int, trpls []*triple.Triple) ([]*triple.Triple, error) {
	if *left < 1 {
		return trpls, nil
	}
	for i, last := 0, *left <= t.branch; i < t.branch; i++ {
		offspring, err := t.newNode(i, parent.ID().String())
		if err != nil {
			return trpls, err
		}
		trpl, err := t.newTriple(parent, offspring)
		if err != nil {
			return trpls, err
		}
		trpls = append(trpls, trpl)
		(*left)--
		if *left < 1 {
			break
		}
		if currentDepth < maxDepth && !last {
			ntrpls, err := t.recurse(offspring, left, currentDepth+1, maxDepth, trpls)
			if err != nil {
				return ntrpls, err
			}
			trpls = ntrpls
		}
		if *left < 1 {
			break
		}
	}
	return trpls, nil
}