create class Topological and move corresponding method from DefaultFixedPointSystem
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3638 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
40d8dab1df
commit
e8f5b0d42d
|
@ -20,16 +20,13 @@ import com.ibm.wala.util.collections.EmptyIterator;
|
|||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.ReverseIterator;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.UnimplementedError;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.GraphIntegrity;
|
||||
import com.ibm.wala.util.graph.INodeWithNumber;
|
||||
import com.ibm.wala.util.graph.NumberedGraph;
|
||||
import com.ibm.wala.util.graph.impl.GraphInverter;
|
||||
import com.ibm.wala.util.graph.impl.SparseNumberedGraph;
|
||||
import com.ibm.wala.util.graph.traverse.DFS;
|
||||
import com.ibm.wala.util.graph.traverse.Topological;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -205,7 +202,7 @@ public class DefaultFixedPointSystem<T extends IVariable> implements IFixedPoint
|
|||
checkGraph();
|
||||
}
|
||||
|
||||
Iterator<INodeWithNumber> order = makeSCCTopOrder(graph);
|
||||
Iterator<INodeWithNumber> order = Topological.makeTopologicalIter(graph);
|
||||
int number = 0;
|
||||
while (order.hasNext()) {
|
||||
Object elt = order.next();
|
||||
|
@ -216,36 +213,6 @@ public class DefaultFixedPointSystem<T extends IVariable> implements IFixedPoint
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an Iterator over all the nodes in the graph, in an order
|
||||
* such that SCCs are visited in topological order.
|
||||
* @throws IllegalArgumentException if graph == null
|
||||
*/
|
||||
public static <T> Iterator<T> makeSCCTopOrder(Graph<T> graph) throws IllegalArgumentException {
|
||||
// the following code ensures a topological order over SCCs.
|
||||
// note that the first two lines of the following give a topological
|
||||
// order for dags, but that can get screwed up by cycles. so
|
||||
// instead, we use Tarjan's SCC algorithm, which happens to
|
||||
// visit nodes in an order consistent with a top. order over SCCs.
|
||||
|
||||
if (graph == null) {
|
||||
throw new IllegalArgumentException("graph == null");
|
||||
}
|
||||
// finish time is post-order
|
||||
// note that if you pay attention only to the first representative
|
||||
// of each SCC discovered, we have a top. order of these SCC
|
||||
// representatives
|
||||
Iterator<T> finishTime = DFS.iterateFinishTime(graph);
|
||||
// reverse postorder is usual topological sort.
|
||||
Iterator<T> rev = ReverseIterator.reverse(finishTime);
|
||||
// the following statement helps out the GC; note that finishTime holds
|
||||
// on to a large array
|
||||
finishTime = null;
|
||||
Graph<T> G_T = GraphInverter.invert(graph);
|
||||
Iterator<T> order = DFS.iterateFinishTime(G_T, rev);
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* check that this graph is well-formed
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.Map;
|
|||
|
||||
import com.ibm.wala.fixedpoint.impl.AbstractOperator;
|
||||
import com.ibm.wala.fixedpoint.impl.AbstractStatement;
|
||||
import com.ibm.wala.fixedpoint.impl.DefaultFixedPointSystem;
|
||||
import com.ibm.wala.fixedpoint.impl.GeneralStatement;
|
||||
import com.ibm.wala.fixedpoint.impl.UnaryOperator;
|
||||
import com.ibm.wala.fixedpoint.impl.UnaryStatement;
|
||||
|
@ -41,6 +40,7 @@ import com.ibm.wala.util.graph.NumberedGraph;
|
|||
import com.ibm.wala.util.graph.NumberedNodeManager;
|
||||
import com.ibm.wala.util.graph.impl.DelegatingNumberedNodeManager;
|
||||
import com.ibm.wala.util.graph.impl.SparseNumberedEdgeManager;
|
||||
import com.ibm.wala.util.graph.traverse.Topological;
|
||||
import com.ibm.wala.util.heapTrace.HeapTracer;
|
||||
import com.ibm.wala.util.intset.BasicNaturalRelation;
|
||||
import com.ibm.wala.util.intset.IBinaryNaturalRelation;
|
||||
|
@ -429,7 +429,7 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
|
|||
public void reorder() {
|
||||
VariableGraphView graph = new VariableGraphView();
|
||||
|
||||
Iterator<PointsToSetVariable> order = DefaultFixedPointSystem.makeSCCTopOrder(graph);
|
||||
Iterator<PointsToSetVariable> order = Topological.makeTopologicalIter(graph);
|
||||
|
||||
int number = 0;
|
||||
while (order.hasNext()) {
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.util.graph.traverse;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.collections.ReverseIterator;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.impl.GraphInverter;
|
||||
|
||||
/**
|
||||
* Utilities for iterating over graphs in topological order.
|
||||
*
|
||||
*/
|
||||
public class Topological {
|
||||
|
||||
/**
|
||||
* Build an Iterator over all the nodes in the graph, in an order such that SCCs are visited in topological order.
|
||||
*
|
||||
* @throws IllegalArgumentException if graph == null
|
||||
*/
|
||||
public static <T> Iterator<T> makeTopologicalIter(Graph<T> graph) throws IllegalArgumentException {
|
||||
// the following code ensures a topological order over SCCs.
|
||||
// note that the first two lines of the following give a topological
|
||||
// order for dags, but that can get screwed up by cycles. so
|
||||
// instead, we use Tarjan's SCC algorithm, which happens to
|
||||
// visit nodes in an order consistent with a top. order over SCCs.
|
||||
|
||||
if (graph == null) {
|
||||
throw new IllegalArgumentException("graph == null");
|
||||
}
|
||||
// finish time is post-order
|
||||
// note that if you pay attention only to the first representative
|
||||
// of each SCC discovered, we have a top. order of these SCC
|
||||
// representatives
|
||||
Iterator<T> finishTime = DFS.iterateFinishTime(graph);
|
||||
// reverse postorder is usual topological sort.
|
||||
Iterator<T> rev = ReverseIterator.reverse(finishTime);
|
||||
// the following statement helps out the GC; note that finishTime holds
|
||||
// on to a large array
|
||||
finishTime = null;
|
||||
Graph<T> G_T = GraphInverter.invert(graph);
|
||||
Iterator<T> order = DFS.iterateFinishTime(G_T, rev);
|
||||
return order;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue