traverseVertically method

Set<String> traverseVertically(
  1. NodeInput node,
  2. Set<String> branchSet,
  3. Set<String> totalSet
)

Implementation

Set<String> traverseVertically(
    NodeInput node, Set<String> branchSet, Set<String> totalSet) {
  if (branchSet.contains(node.id)) {
    throw 'duplicate incomes for node id ${node.id}';
  }
  branchSet.add(node.id);
  totalSet.add(node.id);
  node.next.forEach((out) {
    if (this.isLoopEdge(node.id, out.outcome)) {
      return;
    }
    if (branchSet.contains((out.outcome))) {
      addUniqueRelation(this.loopsByNodeIdMap, node.id, out.outcome);
      return;
    }
    addUniqueRelation(incomesByNodeIdMap, out.outcome, node.id);
    addUniqueRelation(outcomesByNodeIdMap, node.id, out.outcome);
    final nextNode = this.nodesMap[out.outcome];
    if (nextNode == null) {
      throw 'node ${out.outcome} not found';
    }
    if (totalSet.contains(out.outcome)) return;
    totalSet =
        this.traverseVertically(nextNode, Set.from(branchSet), totalSet);
  });
  return totalSet;
}