void () { myOutRoots = new HashMap<>(); for (Node node : mySortedNodes) { myProgressIndicator.checkCanceled(); List<HeapNode<Node>> heapNodes = new ArrayList<>(); Collection<GraphEdge<Node>> edges = myNonTreeEdges.get(node); if (edges.isEmpty()) continue; HeapNode<Node> root = null; for (GraphEdge<Node> edge : edges) { HeapNode<Node> heapNode = new HeapNode<>(edge); heapNodes.add(heapNode); if (root == null || root.myEdge.getDelta() > heapNode.myEdge.getDelta()) { root = heapNode; } } heapNodes.remove(root); myOutRoots.put(node, root); if (!heapNodes.isEmpty()) { for (int j = 1; j < heapNodes.size(); j++) { HeapNode<Node> heapNode = heapNodes.get(j); HeapNode<Node> parent = heapNodes.get((j+1)/2 - 1); parent.myChildren[(j+1) % 2] = heapNode; } for (int j = heapNodes.size() / 2 - 1; j >= 0; j--) { heapify(heapNodes.get(j)); } root.myChildren[2] = heapNodes.get(0); } } }