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
This commit is contained in:
parent
553ab68efa
commit
7fe479ee82
|
@ -15,14 +15,10 @@ import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.ibm.wala.util.collections.HashSetFactory;
|
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.BasicNaturalRelation;
|
||||||
import com.ibm.wala.util.intset.IBinaryNaturalRelation;
|
import com.ibm.wala.util.intset.IBinaryNaturalRelation;
|
||||||
import com.ibm.wala.util.intset.IntIterator;
|
import com.ibm.wala.util.intset.IntIterator;
|
||||||
import com.ibm.wala.util.intset.IntPair;
|
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
|
* Utilities for dealing with acyclic subgraphs
|
||||||
|
@ -103,7 +99,7 @@ public class Acyclic {
|
||||||
*/
|
*/
|
||||||
public static <T> Collection<Path> computeAcyclicPaths(NumberedGraph<T> G, T root, T src, T sink, int max) {
|
public static <T> Collection<Path> computeAcyclicPaths(NumberedGraph<T> G, T root, T src, T sink, int max) {
|
||||||
Collection<Path> result = HashSetFactory.make();
|
Collection<Path> result = HashSetFactory.make();
|
||||||
SubGraph<T> acyclic = new SubGraph<T>(G, computeBackEdges(G, root));
|
EdgeFilteredNumberedGraph<T> acyclic = new EdgeFilteredNumberedGraph<T>(G, computeBackEdges(G, root));
|
||||||
|
|
||||||
Collection<Path> worklist = HashSetFactory.make();
|
Collection<Path> worklist = HashSetFactory.make();
|
||||||
Path sinkPath = Path.make(G.getNumber(sink));
|
Path sinkPath = Path.make(G.getNumber(sink));
|
||||||
|
@ -123,96 +119,4 @@ public class Acyclic {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SubGraph<T> extends AbstractNumberedGraph<T> {
|
|
||||||
|
|
||||||
private final NumberedGraph<T> delegate;
|
|
||||||
|
|
||||||
private final IBinaryNaturalRelation ignoreEdges;
|
|
||||||
|
|
||||||
private final Edges edges;
|
|
||||||
|
|
||||||
SubGraph(NumberedGraph<T> delegate, IBinaryNaturalRelation ignoreEdges) {
|
|
||||||
super();
|
|
||||||
this.delegate = delegate;
|
|
||||||
this.ignoreEdges = ignoreEdges;
|
|
||||||
this.edges = new Edges();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected NumberedEdgeManager<T> getEdgeManager() {
|
|
||||||
return edges;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class Edges implements NumberedEdgeManager<T> {
|
|
||||||
|
|
||||||
public void addEdge(T src, T dst) {
|
|
||||||
Assertions.UNREACHABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPredNodeCount(T N) {
|
|
||||||
Assertions.UNREACHABLE();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<T> getPredNodes(T N) {
|
|
||||||
Assertions.UNREACHABLE();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSuccNodeCount(T N) {
|
|
||||||
Assertions.UNREACHABLE();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<T> 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<T> getNodeManager() {
|
|
||||||
return delegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<T> extends AbstractNumberedGraph<T> {
|
||||||
|
|
||||||
|
private final NumberedGraph<T> 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<T> delegate, IBinaryNaturalRelation ignoreEdges) {
|
||||||
|
super();
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.ignoreEdges = ignoreEdges;
|
||||||
|
this.edges = new Edges();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NumberedEdgeManager<T> getEdgeManager() {
|
||||||
|
return edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class Edges implements NumberedEdgeManager<T> {
|
||||||
|
|
||||||
|
public void addEdge(T src, T dst) {
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPredNodeCount(T N) {
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> getPredNodes(T N) {
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSuccNodeCount(T N) {
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> 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<T> getNodeManager() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue