private Map<V, Depth> assignDepths(V root, List<V> sorted) {

		Set<V> visited = new HashSet<>();
		Map<V, Depth> depthMap = LazyMap.lazyMap(new HashMap<>(), k -> new Depth());

		depthMap.put(root, new Depth());
		for (V parent : sorted) {
			visited.add(parent);
			Depth parentDepth = depthMap.get(parent);
			List<E> edges = new ArrayList<>();
			Collection<E> out = graph.getOutEdges(parent);
			if (out != null) {
				edges.addAll(out);
			}
			edges.sort(edgeComparator);
			for (E e : edges) {
				V child = e.getEnd();
				if (visited.contains(child)) {
					continue;		// loop backs are ignored
				}
				Depth childDepth = depthMap.get(child);
				childDepth.adjustDepth(parentDepth);
			}
		}
		return depthMap;
	}
Sorts the vertices in this graph topologically.

@param root the start node for traversing the graph (will always be the first node in the
resulting list)
@return a list of vertices reachable from the given root vertex, sorted topologically
Ghidra/Framework/Graph/src/main/java/ghidra/graph/GraphToTreeAlgorithm.java