getNodeLevel method

  1. @override
int getNodeLevel(
  1. Node node
)
override

Returns the depth of the specified vertex.

Performs a breadth-first search to find the vertex. Upon finding a match, it stops the search and returns the depth of the vertex.

Implementation

@override
int getNodeLevel(Node node) {
  bool found = false;
  final level = visitBreadth((n) {
    if (n == node) {
      found = true;
      return VisitResult.breakVisit;
    }
    return VisitResult.continueVisit;
  });
  return found ? level : -1;
}