[platform] makes shortest path finders accept semi-graphs

This commit is contained in:
Roman Shevchenko
2018-07-26 13:35:36 +02:00
parent 3c95127f6c
commit 6890e5a029
2 changed files with 21 additions and 8 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.graph.impl;
import com.intellij.openapi.diagnostic.Logger;
@@ -7,6 +7,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.util.containers.FList;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.graph.Graph;
import com.intellij.util.graph.InboundSemiGraph;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
@@ -20,7 +21,7 @@ import java.util.*;
*/
public class KShortestPathsFinder<Node> {
private static final Logger LOG = Logger.getInstance("#com.intellij.util.graph.impl.KShortestPathsFinder");
private final Graph<Node> myGraph;
private final InboundSemiGraph<Node> myGraph;
private final Node myStart;
private final Node myFinish;
private final ProgressIndicator myProgressIndicator;
@@ -30,11 +31,18 @@ public class KShortestPathsFinder<Node> {
private Map<Node, HeapNode<Node>> myOutRoots;
private Map<Node,Heap<Node>> myHeaps;
public KShortestPathsFinder(@NotNull Graph<Node> graph, @NotNull Node start, @NotNull Node finish, @NotNull ProgressIndicator progressIndicator) {
public KShortestPathsFinder(@NotNull Graph<Node> graph, @NotNull Node start, @NotNull Node finish, @NotNull ProgressIndicator progress) {
this(((InboundSemiGraph<Node>)graph), start, finish, progress);
}
public KShortestPathsFinder(@NotNull InboundSemiGraph<Node> graph,
@NotNull Node start,
@NotNull Node finish,
@NotNull ProgressIndicator progress) {
myGraph = graph;
myStart = start;
myFinish = finish;
myProgressIndicator = progressIndicator;
myProgressIndicator = progress;
}
private void computeDistancesToTarget() {
@@ -309,4 +317,4 @@ public class KShortestPathsFinder<Node> {
return new HeapNode<>(this);
}
}
}
}
@@ -1,7 +1,8 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.graph.impl;
import com.intellij.util.graph.Graph;
import com.intellij.util.graph.InboundSemiGraph;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -10,12 +11,15 @@ import java.util.*;
* @author nik
*/
public class ShortestPathFinder<Node> {
private final Graph<Node> myGraph;
private final InboundSemiGraph<Node> myGraph;
public ShortestPathFinder(Graph<Node> graph) {
myGraph = graph;
}
public ShortestPathFinder(InboundSemiGraph<Node> graph) {
myGraph = graph;
}
@Nullable
public List<Node> findPath(Node start, Node finish) {
@@ -44,6 +48,7 @@ public class ShortestPathFinder<Node> {
if (!found) {
return null;
}
List<Node> path = new ArrayList<>();
Node current = start;
while (!current.equals(finish)) {
@@ -53,4 +58,4 @@ public class ShortestPathFinder<Node> {
path.add(finish);
return path;
}
}
}