From 7fe479ee82e44ab6017cc5dbb4a813b8de76e277 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Tue, 3 Apr 2012 19:09:50 +0000 Subject: [PATCH] extract class for an edge-filtered graph view git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4551 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/com/ibm/wala/util/graph/Acyclic.java | 98 +------------- .../util/graph/EdgeFilteredNumberedGraph.java | 120 ++++++++++++++++++ 2 files changed, 121 insertions(+), 97 deletions(-) create mode 100644 com.ibm.wala.util/src/com/ibm/wala/util/graph/EdgeFilteredNumberedGraph.java diff --git a/com.ibm.wala.util/src/com/ibm/wala/util/graph/Acyclic.java b/com.ibm.wala.util/src/com/ibm/wala/util/graph/Acyclic.java index c6bcc1886..a9865724e 100644 --- a/com.ibm.wala.util/src/com/ibm/wala/util/graph/Acyclic.java +++ b/com.ibm.wala.util/src/com/ibm/wala/util/graph/Acyclic.java @@ -15,14 +15,10 @@ import java.util.Iterator; import java.util.Set; import com.ibm.wala.util.collections.HashSetFactory; -import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.intset.BasicNaturalRelation; import com.ibm.wala.util.intset.IBinaryNaturalRelation; import com.ibm.wala.util.intset.IntIterator; import com.ibm.wala.util.intset.IntPair; -import com.ibm.wala.util.intset.IntSet; -import com.ibm.wala.util.intset.MutableIntSet; -import com.ibm.wala.util.intset.MutableSparseIntSet; /** * Utilities for dealing with acyclic subgraphs @@ -103,7 +99,7 @@ public class Acyclic { */ public static Collection computeAcyclicPaths(NumberedGraph G, T root, T src, T sink, int max) { Collection result = HashSetFactory.make(); - SubGraph acyclic = new SubGraph(G, computeBackEdges(G, root)); + EdgeFilteredNumberedGraph acyclic = new EdgeFilteredNumberedGraph(G, computeBackEdges(G, root)); Collection worklist = HashSetFactory.make(); Path sinkPath = Path.make(G.getNumber(sink)); @@ -123,96 +119,4 @@ public class Acyclic { return result; } - - private static class SubGraph extends AbstractNumberedGraph { - - private final NumberedGraph delegate; - - private final IBinaryNaturalRelation ignoreEdges; - - private final Edges edges; - - SubGraph(NumberedGraph delegate, IBinaryNaturalRelation ignoreEdges) { - super(); - this.delegate = delegate; - this.ignoreEdges = ignoreEdges; - this.edges = new Edges(); - } - - @Override - protected NumberedEdgeManager getEdgeManager() { - return edges; - } - - private final class Edges implements NumberedEdgeManager { - - public void addEdge(T src, T dst) { - Assertions.UNREACHABLE(); - } - - public int getPredNodeCount(T N) { - Assertions.UNREACHABLE(); - return 0; - } - - public Iterator getPredNodes(T N) { - Assertions.UNREACHABLE(); - return null; - } - - public int getSuccNodeCount(T N) { - Assertions.UNREACHABLE(); - return 0; - } - - public Iterator getSuccNodes(T N) { - Assertions.UNREACHABLE(); - return null; - } - - public boolean hasEdge(T src, T dst) { - Assertions.UNREACHABLE(); - return false; - } - - public void removeAllIncidentEdges(T node) throws UnsupportedOperationException { - Assertions.UNREACHABLE(); - } - - public void removeEdge(T src, T dst) throws UnsupportedOperationException { - Assertions.UNREACHABLE(); - } - - public void removeIncomingEdges(T node) throws UnsupportedOperationException { - Assertions.UNREACHABLE(); - } - - public void removeOutgoingEdges(T node) throws UnsupportedOperationException { - Assertions.UNREACHABLE(); - } - - public IntSet getPredNodeNumbers(T node) { - IntSet s = delegate.getPredNodeNumbers(node); - MutableIntSet result = MutableSparseIntSet.makeEmpty(); - for (IntIterator it = s.intIterator(); it.hasNext();) { - int y = it.next(); - if (!ignoreEdges.contains(y, getNumber(node))) { - result.add(y); - } - } - return result; - } - - public IntSet getSuccNodeNumbers(T node) { - Assertions.UNREACHABLE(); - return null; - } - - } - - @Override - protected NumberedNodeManager getNodeManager() { - return delegate; - } - } } diff --git a/com.ibm.wala.util/src/com/ibm/wala/util/graph/EdgeFilteredNumberedGraph.java b/com.ibm.wala.util/src/com/ibm/wala/util/graph/EdgeFilteredNumberedGraph.java new file mode 100644 index 000000000..bc91b0ae8 --- /dev/null +++ b/com.ibm.wala.util/src/com/ibm/wala/util/graph/EdgeFilteredNumberedGraph.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008 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; + +import java.util.Iterator; + +import com.ibm.wala.util.debug.Assertions; +import com.ibm.wala.util.intset.IBinaryNaturalRelation; +import com.ibm.wala.util.intset.IntIterator; +import com.ibm.wala.util.intset.IntSet; +import com.ibm.wala.util.intset.MutableIntSet; +import com.ibm.wala.util.intset.MutableSparseIntSet; + +/** + * View of a {@link NumberedGraph} in which some edges have been filtered out + */ +public class EdgeFilteredNumberedGraph extends AbstractNumberedGraph { + + private final NumberedGraph delegate; + + private final IBinaryNaturalRelation ignoreEdges; + + private final Edges edges; + + /** + * + * @param delegate the underlying graph + * @param ignoreEdges relation specifying which edges should be filtered out + */ + public EdgeFilteredNumberedGraph(NumberedGraph delegate, IBinaryNaturalRelation ignoreEdges) { + super(); + this.delegate = delegate; + this.ignoreEdges = ignoreEdges; + this.edges = new Edges(); + } + + @Override + protected NumberedEdgeManager getEdgeManager() { + return edges; + } + + private final class Edges implements NumberedEdgeManager { + + public void addEdge(T src, T dst) { + Assertions.UNREACHABLE(); + } + + public int getPredNodeCount(T N) { + Assertions.UNREACHABLE(); + return 0; + } + + public Iterator getPredNodes(T N) { + Assertions.UNREACHABLE(); + return null; + } + + public int getSuccNodeCount(T N) { + Assertions.UNREACHABLE(); + return 0; + } + + public Iterator getSuccNodes(T N) { + Assertions.UNREACHABLE(); + return null; + } + + public boolean hasEdge(T src, T dst) { + Assertions.UNREACHABLE(); + return false; + } + + public void removeAllIncidentEdges(T node) throws UnsupportedOperationException { + Assertions.UNREACHABLE(); + } + + public void removeEdge(T src, T dst) throws UnsupportedOperationException { + Assertions.UNREACHABLE(); + } + + public void removeIncomingEdges(T node) throws UnsupportedOperationException { + Assertions.UNREACHABLE(); + } + + public void removeOutgoingEdges(T node) throws UnsupportedOperationException { + Assertions.UNREACHABLE(); + } + + public IntSet getPredNodeNumbers(T node) { + IntSet s = delegate.getPredNodeNumbers(node); + MutableIntSet result = MutableSparseIntSet.makeEmpty(); + for (IntIterator it = s.intIterator(); it.hasNext();) { + int y = it.next(); + if (!ignoreEdges.contains(y, getNumber(node))) { + result.add(y); + } + } + return result; + } + + public IntSet getSuccNodeNumbers(T node) { + Assertions.UNREACHABLE(); + return null; + } + + } + + @Override + protected NumberedNodeManager getNodeManager() { + return delegate; + } +} \ No newline at end of file