visit method

bool visit(
  1. T n
)

Implementation

bool visit(T n) {
  if (_perm.contains(n)) {
    return true;
  }
  if (_temp.contains(n)) {
    // cycle detected!
    return false;
  }

  _temp.add(n);

  final dependents = dependentsOf(n);
  for (final T d in dependents) {
    if (!visit(d)) {
      return false;
    }
  }
  _perm.add(n);

  // Note that we're adding in reverse order intentionally so we don't have to
  // keep inserting at the start and re-alloc-ing the whole list...It does
  // mean we need to reverse the list afterwards.
  _order.add(n);

  return true;
}