slight generalization of duplicate to add copyInto

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1036 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
dolby-oss 2007-05-02 04:15:35 +00:00
parent 9cdd4f4791
commit b120c59abf
1 changed files with 8 additions and 4 deletions

View File

@ -70,15 +70,19 @@ public class SlowSparseNumberedGraph<T> extends AbstractNumberedGraph<T> {
*/
public static <T> SlowSparseNumberedGraph<T> duplicate(Graph<T> g) {
SlowSparseNumberedGraph<T> result = new SlowSparseNumberedGraph<T>();
copyInto(g, result);
return result;
}
public static <T> void copyInto(Graph<T> g, Graph<T> into) {
for (Iterator<? extends T> it = g.iterator(); it.hasNext();) {
result.addNode(it.next());
into.addNode(it.next());
}
for (Iterator<? extends T> it = g.iterator(); it.hasNext();) {
T n = it.next();
for (Iterator<? extends T> it2 = g.getSuccNodes(n); it2.hasNext();) {
result.addEdge(n, it2.next());
into.addEdge(n, it2.next());
}
}
return result;
}
}
}