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((outcomeId) {
    if (this.isLoopEdge(node.id, outcomeId)) {
      return;
    }
    if (branchSet.contains((outcomeId))) {
      addUniqueRelation(this.loopsByNodeIdMap, node.id, outcomeId);
      return;
    }
    addUniqueRelation(incomesByNodeIdMap, outcomeId, node.id);
    addUniqueRelation(outcomesByNodeIdMap, node.id, outcomeId);
    final nextNode = this.nodesMap[outcomeId];
    if (nextNode == null) {
      throw 'node $outcomeId not found';
    }
    totalSet =
        this.traverseVertically(nextNode, Set.from(branchSet), totalSet);
  });
  return totalSet;
}