Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1626 - deprecated old graph code

dragonmacheraa841485ea80
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/AddableLongDoubleHashtable.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/AddableLongDoubleHashtable.java
index eb433218ce..12a8ed5ca4 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/AddableLongDoubleHashtable.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/AddableLongDoubleHashtable.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +24,7 @@ import ghidra.util.exception.NoValueException;
* to the value stored with the key rather than replacing the value.
*
*/
+@Deprecated(forRemoval = true, since = "10.2")
public class AddableLongDoubleHashtable extends LongDoubleHashtable {
public AddableLongDoubleHashtable() {
super();
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DepthFirstSearch.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DepthFirstSearch.java
index a5ecfe9319..fc5a8bd0eb 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DepthFirstSearch.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DepthFirstSearch.java
@@ -24,403 +24,353 @@ import java.util.*;
*
*
*/
-public class DepthFirstSearch
-{
- private DirectedGraph graph;
- private List<Vertex> seedsUsed;
- private Set<Vertex> unseen;
- private Set<Vertex> finished;
- private Stack<KeyedObject> pending;
- private LinkedList<Vertex> finishListInReverseOrder;
- private List<Edge> backEdges;
- private List<Edge> treeEdges;
- //private List forwardAndCrossEdges;
+@Deprecated(since = "10.2")
+public class DepthFirstSearch {
+ private DirectedGraph graph;
+ private List<Vertex> seedsUsed;
+ private Set<Vertex> unseen;
+ private Set<Vertex> finished;
+ private Stack<KeyedObject> pending;
+ private LinkedList<Vertex> finishListInReverseOrder;
+ private List<Edge> backEdges;
+ private List<Edge> treeEdges;
+ //private List forwardAndCrossEdges;
- /**
- * Upon creation a depth first search of the given graph is performed.
- *
- * @param graph The graph to search
- * @param initialSeeds The vertices used to start the search
- * @param getAdditionalSeedsIfNeeded If true, when searching from the initial
- * seeds does not find all vertices in the graph, additional start vertices will
- * be selected until every vertex is the graph has been found.
- * @param goForward Follow edges in their specifed direction
- * @param goBackward Follow edges in the opposite of their specified direction.
- */
- public DepthFirstSearch( DirectedGraph graph,
- Vertex[] initialSeeds,
- boolean getAdditionalSeedsIfNeeded,
- boolean goForward,
- boolean goBackward)
- {
+ /**
+ * Upon creation a depth first search of the given graph is performed.
+ *
+ * @param graph The graph to search
+ * @param initialSeeds The vertices used to start the search
+ * @param getAdditionalSeedsIfNeeded If true, when searching from the initial
+ * seeds does not find all vertices in the graph, additional start vertices will
+ * be selected until every vertex is the graph has been found.
+ * @param goForward Follow edges in their specifed direction
+ * @param goBackward Follow edges in the opposite of their specified direction.
+ */
+ public DepthFirstSearch(DirectedGraph graph,
+ Vertex[] initialSeeds,
+ boolean getAdditionalSeedsIfNeeded,
+ boolean goForward,
+ boolean goBackward) {
- if( !goForward && !goBackward )
- {
- return;
- }
- this.graph = graph;
- seedsUsed = new ArrayList<Vertex>();
- unseen = graph.vertices().toSet();
- finished = new HashSet<Vertex>( graph.numVertices() );
- pending = new Stack<KeyedObject>(); //MyStack() for debugging
+ if (!goForward && !goBackward) {
+ return;
+ }
+ this.graph = graph;
+ seedsUsed = new ArrayList<>();
+ unseen = graph.vertices().toSet();
+ finished = new HashSet<>(graph.numVertices());
+ pending = new Stack<>(); //MyStack() for debugging
+ finishListInReverseOrder = new LinkedList<>();
+ backEdges = new ArrayList<>(graph.numEdges() / 5);
+ treeEdges = new ArrayList<>(graph.numEdges() / 5);
+ Vertex v;
+ Edge e;
+ Set<Edge> edges = null;
+ Object o;
+ Iterator<Edge> edgeIter;
+ boolean done = true;
- finishListInReverseOrder = new LinkedList<Vertex>();
- backEdges = new ArrayList<Edge>( graph.numEdges()/5 );
- treeEdges = new ArrayList<Edge>( graph.numEdges()/5 );
- Vertex v;
- Edge e;
- Set<Edge> edges = null;
- Object o;
- Iterator<Edge> edgeIter;
- boolean done = true;
+ Vertex[] seeds = initialSeeds;
- Vertex[] seeds = initialSeeds;
+ if (goForward && !goBackward) {
+ do {
+ for (Vertex seed : seeds) {
+ v = seed;
+ if (isUnseen(v)) {
+ seedsUsed.add(v);
+ pending.push(v);
+ unseen.remove(v);
+ while (!pending.isEmpty()) {
+ o = pending.peek();
+ if (o instanceof Vertex) {
+ v = (Vertex) o;
+ edges = graph.getOutgoingEdges(v);
+ edgeIter = edges.iterator();
+ while (edgeIter.hasNext()) {
+ pending.push(edgeIter.next());
+ }
+ if (edges.size() == 0) {
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ pending.pop();
+ }
+ }
+ else //it's an edge
+ {
+ e = (Edge) pending.pop();
+ v = e.to();
+ if (isUnseen(v)) {
+ pending.push(e);
+ pending.push(v);
+ treeEdges.add(e);
+ unseen.remove(v);
+ }
+ else if (isCompleted(v)) {
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
+ else //it is pending
+ {
+ backEdges.add(e);
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
- if( goForward && !goBackward )
- {
- do
- {
- for( int i=0; i< seeds.length; i++ )
- {
- v = seeds[i];
- if( isUnseen( v ) )
- {
- seedsUsed.add( v );
- pending.push( v );
- unseen.remove( v );
- while( !pending.isEmpty() )
- {
- o = pending.peek();
- if( o instanceof Vertex )
- {
- v = (Vertex)o;
- edges = graph.getOutgoingEdges( v );
- edgeIter = edges.iterator();
- while( edgeIter.hasNext() )
- {
- pending.push( edgeIter.next() );
- }
- if( edges.size() == 0 )
- {
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- pending.pop();
- }
- }
- else //it's an edge
- {
- e = (Edge)pending.pop();
- v = e.to();
- if( isUnseen( v ) )
- {
- pending.push( e );
- pending.push( v );
- treeEdges.add( e );
- unseen.remove( v );
- }
- else if( isCompleted( v ) )
- {
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
- else //it is pending
- {
- backEdges.add( e );
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
+ }//peek at top of stack
+ } //while stack is not empty
+ }//if next seed is unseen
+ }//while there are more seeds
- }//peek at top of stack
- } //while stack is not empty
- }//if next seed is unseen
- }//while there are more seeds
+ //If we need to search the whole graph (not just what is reachable from
+ //the given seeds, then repeat the procedure using an iterator on list
+ //derived from unseen rather than seeds. The iterator goes through
+ //vertices in increasing key order.
+ done = true;
+ if (getAdditionalSeedsIfNeeded && !unseen.isEmpty()) {
+ seeds = unseen.toArray(new Vertex[unseen.size()]);
+ done = false;
+ }
+ }
+ while (!done);
+ }
+ else if (!goForward && goBackward) {
+ do {
+ for (Vertex seed : seeds) {
+ v = seed;
+ if (isUnseen(v)) {
+ seedsUsed.add(v);
+ pending.push(v);
+ unseen.remove(v);
+ while (!pending.isEmpty()) {
+ o = pending.peek();
+ if (o instanceof Vertex) {
+ v = (Vertex) o;
+ edges = graph.getIncomingEdges(v);
+ edgeIter = edges.iterator();
+ while (edgeIter.hasNext()) {
+ pending.push(edgeIter.next());
+ }
+ if (edges.size() == 0) {
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ pending.pop();
+ }
+ }
+ else //it's an edge
+ {
+ e = (Edge) pending.pop();
+ v = e.from();
+ if (isUnseen(v)) {
+ pending.push(e);
+ pending.push(v);
+ treeEdges.add(e);
+ unseen.remove(v);
+ }
+ else if (isCompleted(v)) {
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
+ else //it is pending
+ {
+ backEdges.add(e);
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
- //If we need to search the whole graph (not just what is reachable from
- //the given seeds, then repeat the procedure using an iterator on list
- //derived from unseen rather than seeds. The iterator goes through
- //vertices in increasing key order.
- done = true;
- if( getAdditionalSeedsIfNeeded && !unseen.isEmpty() )
- {
- seeds = unseen.toArray(new Vertex[unseen.size()]);
- done = false;
- }
- }while( !done );
- }
- else if( !goForward && goBackward )
- {
- do
- {
- for( int i=0; i< seeds.length; i++ )
- {
- v = seeds[i];
- if( isUnseen( v ) )
- {
- seedsUsed.add( v );
- pending.push( v );
- unseen.remove( v );
- while( !pending.isEmpty() )
- {
- o = pending.peek();
- if( o instanceof Vertex )
- {
- v = (Vertex)o;
- edges = graph.getIncomingEdges( v );
- edgeIter = edges.iterator();
- while( edgeIter.hasNext() )
- {
- pending.push( edgeIter.next() );
- }
- if( edges.size() == 0 )
- {
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- pending.pop();
- }
- }
- else //it's an edge
- {
- e = (Edge)pending.pop();
- v = e.from();
- if( isUnseen( v ) )
- {
- pending.push( e );
- pending.push( v );
- treeEdges.add( e );
- unseen.remove( v );
- }
- else if( isCompleted( v ) )
- {
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
- else //it is pending
- {
- backEdges.add( e );
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
+ }//peek at top of stack
+ } //while stack is not empty
+ }//if next seed is unseen
+ }//while there are more seeds
- }//peek at top of stack
- } //while stack is not empty
- }//if next seed is unseen
- }//while there are more seeds
+ //If we need to search the whole graph (not just what is reachable from
+ //the given seeds, then repeat the procedure using an iterator on list
+ //derived from unseen rather than seeds. The iterator goes through
+ //vertices in increasing key order.
+ done = true;
+ if (getAdditionalSeedsIfNeeded && !unseen.isEmpty()) {
+ seeds = unseen.toArray(new Vertex[unseen.size()]);
+ done = false;
+ }
+ }
+ while (!done);
- //If we need to search the whole graph (not just what is reachable from
- //the given seeds, then repeat the procedure using an iterator on list
- //derived from unseen rather than seeds. The iterator goes through
- //vertices in increasing key order.
- done = true;
- if( getAdditionalSeedsIfNeeded && !unseen.isEmpty() )
- {
- seeds = unseen.toArray(new Vertex[unseen.size()]);
- done = false;
- }
- }while( !done );
+ }
+ else// goForward && goBackward
+ {
+ do {
+ for (Vertex seed : seeds) {
+ v = seed;
+ if (isUnseen(v)) {
+ seedsUsed.add(v);
+ pending.push(v);
+ unseen.remove(v);
+ while (!pending.isEmpty()) {
+ o = pending.peek();
+ if (o instanceof Vertex) {
+ v = (Vertex) o;
+ edges = graph.getOutgoingEdges(v);
+ edges.addAll(graph.getIncomingEdges(v));
+ edgeIter = edges.iterator();
+ while (edgeIter.hasNext()) {
+ pending.push(edgeIter.next());
+ }
+ if (edges.size() == 0) {
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ pending.pop();
+ }
+ }
+ else //its an edge
+ {
+ e = (Edge) pending.pop();
+ ListIterator<KeyedObject> li = pending.listIterator(pending.size());
+ v = null;
+ while (li.hasPrevious() && (v == null)) {
+ o = li.previous();
+ if (o instanceof Vertex) {
+ v = (Vertex) o;
+ }
+ }
+ if (isUnseen(v)) {
+ pending.push(e);
+ pending.push(v);
+ treeEdges.add(e);
+ unseen.remove(v);
+ }
+ else if (isCompleted(v)) {
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
+ else //it is pending
+ {
+ backEdges.add(e);
+ if (pending.peek() instanceof Vertex) {
+ v = (Vertex) pending.pop();
+ finished.add(v);
+ finishListInReverseOrder.addFirst(v);
+ }
+ }
- }
- else// goForward && goBackward
- {
- do
- {
- for( int i=0; i< seeds.length; i++ )
- {
- v = seeds[i];
- if( isUnseen( v ) )
- {
- seedsUsed.add( v );
- pending.push( v );
- unseen.remove( v );
- while( !pending.isEmpty() )
- {
- o = pending.peek();
- if( o instanceof Vertex )
- {
- v = (Vertex)o;
- edges = graph.getOutgoingEdges( v );
- edges.addAll( graph.getIncomingEdges( v ) );
- edgeIter = edges.iterator();
- while( edgeIter.hasNext() )
- {
- pending.push( edgeIter.next() );
- }
- if( edges.size() == 0 )
- {
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- pending.pop();
- }
- }
- else //its an edge
- {
- e = (Edge)pending.pop();
- ListIterator<KeyedObject> li = pending.listIterator(pending.size());
- v = null;
- while( li.hasPrevious() && (v == null) )
- {
- o = li.previous();
- if( o instanceof Vertex )
- {
- v = (Vertex)o;
- }
- }
- if( isUnseen( v ) )
- {
- pending.push( e );
- pending.push( v );
- treeEdges.add( e );
- unseen.remove( v );
- }
- else if( isCompleted( v ) )
- {
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
- else //it is pending
- {
- backEdges.add( e );
- if( pending.peek() instanceof Vertex )
- {
- v = (Vertex)pending.pop();
- finished.add( v );
- finishListInReverseOrder.addFirst( v );
- }
- }
+ }//peek at top of stack
+ } //while stack is not empty
+ }//if next seed is unseen
+ }//while there are more seeds
- }//peek at top of stack
- } //while stack is not empty
- }//if next seed is unseen
- }//while there are more seeds
+ //If we need to search the whole graph (not just what is reachable from
+ //the given seeds, then repeat the procedure using an iterator on list
+ //derived from unseen rather than seeds. The iterator goes through
+ //vertices in increasing key order.
+ done = true;
+ if (getAdditionalSeedsIfNeeded && !unseen.isEmpty()) {
+ seeds = unseen.toArray(new Vertex[unseen.size()]);
+ done = false;
+ }
+ }
+ while (!done);
- //If we need to search the whole graph (not just what is reachable from
- //the given seeds, then repeat the procedure using an iterator on list
- //derived from unseen rather than seeds. The iterator goes through
- //vertices in increasing key order.
- done = true;
- if( getAdditionalSeedsIfNeeded && !unseen.isEmpty() )
- {
- seeds = unseen.toArray(new Vertex[unseen.size()]);
- done = false;
- }
- }while( !done );
+ }
+ }
- }
- }
+ /**
+ * Return true if the vertex has not yet been discovered in the depth first
+ * search.
+ */
+ public boolean isUnseen(Vertex v) {
+ return unseen.contains(v);
+ }
- /**
- * Return true if the vertex has not yet been discovered in the depth first
- * search.
- */
- public boolean isUnseen( Vertex v )
- {
- return unseen.contains( v );
- }
+ /**
+ * Return true if the vertex has completed its role in the depth first
+ * search.
+ */
+ public boolean isCompleted(Vertex v) {
+ return finished.contains(v);
+ }
- /**
- * Return true if the vertex has completed its role in the depth first
- * search.
- */
- public boolean isCompleted( Vertex v )
- {
- return finished.contains( v );
- }
+ /**
+ * Return the back edges found in this depth first search.
+ */
+ public Edge[] backEdges() {
+ return backEdges.toArray(new Edge[backEdges.size()]);
+ }
- /**
- * Return the back edges found in this depth first search.
- */
- public Edge[] backEdges()
- {
- return backEdges.toArray(new Edge[backEdges.size()]);
- }
+ /**
+ * Return the tree edges in this depth first search.
+ */
+ public Edge[] treeEdges() {
+ return treeEdges.toArray(new Edge[treeEdges.size()]);
+ }
- /**
- * Return the tree edges in this depth first search.
- */
- public Edge[] treeEdges()
- {
- return treeEdges.toArray(new Edge[treeEdges.size()]);
- }
+ /**
+ * Return true iff no back edges were found.
+ *
+ * Note that if the graph
+ * is not completely explored the answer is only for the portion
+ * of the graph expored.
+ */
+ public boolean isAcyclic() {
+ return backEdges.isEmpty();
+ }
- /**
- * Return true iff no back edges were found.
- *
- * Note that if the graph
- * is not completely explored the answer is only for the portion
- * of the graph expored.
- */
- public boolean isAcyclic()
- {
- return backEdges.isEmpty();
- }
+ /**
+ * Return true iff the every edge is a tree edge. Will always be false
+ * if the entire graph is not explored.
+ */
+ public boolean isTree() {
+ return (treeEdges.size() == graph.numEdges());
+ }
- /**
- * Return true iff the every edge is a tree edge. Will always be false
- * if the entire graph is not explored.
- */
- public boolean isTree()
- {
- return (treeEdges.size() == graph.numEdges() );
- }
+ /** Returns a topological sort of the directed graph.
+ * Return the vertices in the explored
+ * portion of the graph with the following
+ * property:
+ * <ol>
+ * <li>{@literal If the graph is acyclic then v[i] -> v[j] => i < j .}</li>
+ * <li>If the graph contains cycles, then the above is true except when
+ * (v[i],v[j]) is a back edge.</li>
+ * </ol>
+ *
+ */
+ public Vertex[] topologicalSort() {
+ return finishListInReverseOrder.toArray(new Vertex[finishListInReverseOrder.size()]);
+ }
- /** Returns a topological sort of the directed graph.
- * Return the vertices in the explored
- * portion of the graph with the following
- * property:
- * <ol>
- * <li>{@literal If the graph is acyclic then v[i] -> v[j] => i < j .}</li>
- * <li>If the graph contains cycles, then the above is true except when
- * (v[i],v[j]) is a back edge.</li>
- * </ol>
- *
- */
- public Vertex[] topologicalSort()
- {
- return finishListInReverseOrder.toArray(new Vertex[finishListInReverseOrder.size()]);
- }
+ /**
+ * Return the seeds used in the depth first search.
+ **/
+ List<Vertex> seedsUsed() {
+ return seedsUsed;
+ }
- /**
- * Return the seeds used in the depth first search.
- **/
- List<Vertex> seedsUsed()
- {
- return seedsUsed;
- }
-
- /**
- * Returns a spanning tree (in the form of a DirectedGraph).
- * No claims that the spanning tree returned has any special
- * properties.
- */
- public DirectedGraph spanningTree()
- {
- DirectedGraph g = new DirectedGraph( treeEdges.size() + 1, treeEdges.size() );
- Iterator<Edge> iter = treeEdges.iterator();
- while( iter.hasNext() )
- {
- g.add( iter.next() );
- }
- return g;
- }
+ /**
+ * Returns a spanning tree (in the form of a DirectedGraph).
+ * No claims that the spanning tree returned has any special
+ * properties.
+ */
+ public DirectedGraph spanningTree() {
+ DirectedGraph g = new DirectedGraph(treeEdges.size() + 1, treeEdges.size());
+ Iterator<Edge> iter = treeEdges.iterator();
+ while (iter.hasNext()) {
+ g.add(iter.next());
+ }
+ return g;
+ }
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DirectedGraph.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DirectedGraph.java
index 2da7d13e4d..05d7345044 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DirectedGraph.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DirectedGraph.java
@@ -31,6 +31,14 @@ import ghidra.util.graph.attributes.*;
*
*
*/
+
+//
+// Note: once this lass is no longer used, also remove ghidra.util.graph.attributes
+// Note: once this package is cleaned of deprecated class, move the remaining in-use classes
+// into the graph module. For example, AbstractDependencyGraph and its subclasses should
+// be moved.
+//
+@Deprecated(since = "10.2") // Use GraphFactory
public class DirectedGraph {
private final VertexSet vertices;
private final EdgeSet edges;
@@ -48,8 +56,8 @@ public class DirectedGraph {
public DirectedGraph(int vertexCapacity, int edgeCapacity) {
vertices = new VertexSet(this, vertexCapacity);
edges = new EdgeSet(this, edgeCapacity);
- vertexAttributes = new AttributeManager<Vertex>(vertices);
- edgeAttributes = new AttributeManager<Edge>(edges);
+ vertexAttributes = new AttributeManager<>(vertices);
+ edgeAttributes = new AttributeManager<>(edges);
}
/** Default constructor */
@@ -152,7 +160,7 @@ public class DirectedGraph {
* edges, the number of children and outvalence need not be the same.
*/
public Set<Vertex> getChildren(Vertex v) {
- Set<Vertex> children = new HashSet<Vertex>();
+ Set<Vertex> children = new HashSet<>();
Edge e = vertices.getFirstOutgoingEdge(v);
while (e != null) {
children.add(e.to());
@@ -163,7 +171,7 @@ public class DirectedGraph {
/** Returns the outgoing edges from the given vertex. */
public Set<Edge> getOutgoingEdges(Vertex v) {
- Set<Edge> outgoingEdges = new HashSet<Edge>();
+ Set<Edge> outgoingEdges = new HashSet<>();
Edge e = vertices.getFirstOutgoingEdge(v);
while (e != null) {
outgoingEdges.add(e);
@@ -176,7 +184,7 @@ public class DirectedGraph {
* into the given vertex.
*/
public Set<Vertex> getParents(Vertex v) {
- Set<Vertex> parents = new HashSet<Vertex>();
+ Set<Vertex> parents = new HashSet<>();
Edge e = vertices.getFirstIncomingEdge(v);
while (e != null) {
parents.add(e.from());
@@ -187,7 +195,7 @@ public class DirectedGraph {
/** Returns a Set containing all of the edges to the given vertex. */
public Set<Edge> getIncomingEdges(Vertex v) {
- Set<Edge> incomingEdges = new HashSet<Edge>();
+ Set<Edge> incomingEdges = new HashSet<>();
Edge e = vertices.getFirstIncomingEdge(v);
while (e != null) {
incomingEdges.add(e);
@@ -198,7 +206,7 @@ public class DirectedGraph {
/** Returns all children of the vertices in the given set. */
public Set<Vertex> getChildren(Set<Vertex> vs) {
- Set<Vertex> children = new HashSet<Vertex>();
+ Set<Vertex> children = new HashSet<>();
Vertex v;
Edge e;
Iterator<Vertex> i = vs.iterator();
@@ -215,7 +223,7 @@ public class DirectedGraph {
/** Returns all parents of the vertices in the given set. */
public Set<Vertex> getParents(Set<Vertex> vs) {
- Set<Vertex> parents = new HashSet<Vertex>();
+ Set<Vertex> parents = new HashSet<>();
Edge e;
Vertex v;
Iterator<Vertex> i = vs.iterator();
@@ -234,10 +242,10 @@ public class DirectedGraph {
* Note: The vertex is defined to be a descendant of itself.
*/
public Set<Vertex> getDescendants(Vertex v) {
- Set<Vertex> seeds = new HashSet<Vertex>(11);
+ Set<Vertex> seeds = new HashSet<>(11);
seeds.add(v);
- Set<Vertex> descendants = new HashSet<Vertex>(vertices.size() / 20);
- Set<Vertex> newSeeds = new HashSet<Vertex>();
+ Set<Vertex> descendants = new HashSet<>(vertices.size() / 20);
+ Set<Vertex> newSeeds = new HashSet<>();
Iterator<Vertex> i;
Vertex vertex, child;
Edge e;
@@ -320,9 +328,9 @@ public class DirectedGraph {
public Set<Vertex> getDescendants(Vertex[] seedVertices) {
Edge edge;
Vertex parent, child;
- Set<Vertex> descendants = new HashSet<Vertex>(2 * seedVertices.length);
- Set<Vertex> pending = new HashSet<Vertex>(seedVertices.length);
- Set<Vertex> newlyPending = new HashSet<Vertex>(seedVertices.length);
+ Set<Vertex> descendants = new HashSet<>(2 * seedVertices.length);
+ Set<Vertex> pending = new HashSet<>(seedVertices.length);
+ Set<Vertex> newlyPending = new HashSet<>(seedVertices.length);
for (Vertex seedVertice : seedVertices) {
pending.add(seedVertice);
}
@@ -352,10 +360,10 @@ public class DirectedGraph {
* Note: By definition a vertex is one of its own ancestors.
*/
public Set<Vertex> getAncestors(Vertex v) {
- Set<Vertex> seeds = new HashSet<Vertex>(11);
+ Set<Vertex> seeds = new HashSet<>(11);
seeds.add(v);
- Set<Vertex> ancestors = new HashSet<Vertex>(this.numVertices() / 20);
- Set<Vertex> newSeeds = new HashSet<Vertex>();
+ Set<Vertex> ancestors = new HashSet<>(this.numVertices() / 20);
+ Set<Vertex> newSeeds = new HashSet<>();
Iterator<Vertex> i;
Vertex vertex, parent;
Edge e;
@@ -449,13 +457,13 @@ public class DirectedGraph {
DepthFirstSearch dfsb =
new DepthFirstSearch(this, dfsa.topologicalSort(), true, false, true);
//Err.debug(this, "The number of SCCs is " + dfsb.seedsUsed.size());
- Set<Vertex> sccSeeds = new HashSet<Vertex>(dfsb.seedsUsed());
+ Set<Vertex> sccSeeds = new HashSet<>(dfsb.seedsUsed());
Set<Vertex>[] sccVertices = new Set[sccSeeds.size()]; // triggers unchecked warning
Vertex[] finishOrder = dfsb.topologicalSort();
int n = finishOrder.length;
int j = 0;
for (int i = 0; i < sccSeeds.size(); i++) {
- sccVertices[i] = new HashSet<Vertex>(1);
+ sccVertices[i] = new HashSet<>(1);
do {
//Err.debug(this, Long.toHexString(finishOrder[j].getName() ) + " ");
sccVertices[i].add(finishOrder[j++]);
@@ -475,8 +483,8 @@ public class DirectedGraph {
public Vector<Vertex> getEntryPoints() {
Vertex[] sources = this.vertices().getSources();
- Set<Vertex> entryPointSet = new TreeSet<Vertex>();
- Vector<Vertex> entryPoints = new Vector<Vertex>(sources.length);
+ Set<Vertex> entryPointSet = new TreeSet<>();
+ Vector<Vertex> entryPoints = new Vector<>(sources.length);
for (Vertex source : sources) {
entryPointSet.add(source);
}
@@ -612,9 +620,9 @@ public class DirectedGraph {
* same component a the given vertex.
*/
public Set<Vertex> getVerticesInContainingComponent(Vertex v) {
- Set<Vertex> verticesInComponent = new HashSet<Vertex>();
- Set<Vertex> toDo = new HashSet<Vertex>();
- Set<Vertex> toDoNext = new HashSet<Vertex>();
+ Set<Vertex> verticesInComponent = new HashSet<>();
+ Set<Vertex> toDo = new HashSet<>();
+ Set<Vertex> toDoNext = new HashSet<>();
Set<Vertex> neighborhood;
Iterator<Vertex> i;
Vertex u;
@@ -651,9 +659,9 @@ public class DirectedGraph {
Vertex u, v;
Edge e;
DirectedGraph g;
- Set<Vertex> accountedFor = new HashSet<Vertex>(this.numVertices());
- Set<Vertex> toDo = new HashSet<Vertex>(this.numVertices());
- List<DirectedGraph> components = new ArrayList<DirectedGraph>();
+ Set<Vertex> accountedFor = new HashSet<>(this.numVertices());
+ Set<Vertex> toDo = new HashSet<>(this.numVertices());
+ List<DirectedGraph> components = new ArrayList<>();
GraphIterator<Vertex> vertIter = this.vertexIterator();
Iterator<Vertex> iter;
int i;
@@ -780,7 +788,7 @@ public class DirectedGraph {
* neighbors.
*/
public Set<Vertex> getNeighborhood(Set<Vertex> vs) {
- Set<Vertex> neighborhood = new HashSet<Vertex>(2 * vs.size());
+ Set<Vertex> neighborhood = new HashSet<>(2 * vs.size());
Iterator<Vertex> iter = vs.iterator();
while (iter.hasNext()) {
neighborhood.addAll(getNeighborhood(iter.next()));
@@ -798,7 +806,7 @@ public class DirectedGraph {
/** This method assigns levels in a top-down manner. Sources are on level 0.
*/
public IntegerAttribute<Vertex> getLevels() {
- IntegerAttribute<Vertex> levels = new IntegerAttribute<Vertex>("Levels", this.vertices());
+ IntegerAttribute<Vertex> levels = new IntegerAttribute<>("Levels", this.vertices());
DepthFirstSearch dfs = new DepthFirstSearch(this, this.getSources(), true, true, false);
Vertex[] topologicalSort = dfs.topologicalSort();
int numVertices = this.numVertices();
@@ -935,14 +943,16 @@ public class DirectedGraph {
*/
public Vertex[] getVerticesHavingReferent(Object o) {
int cnt = 0;
- if (o == null)
+ if (o == null) {
return new Vertex[0];
+ }
Vertex[] temp = new Vertex[this.numVertices()];
GraphIterator<Vertex> iter = this.vertexIterator();
while (iter.hasNext()) {
Vertex v = iter.next();
- if (v.referent() != null && v.referent().equals(o))
+ if (v.referent() != null && v.referent().equals(o)) {
temp[cnt++] = v;
+ }
}
Vertex[] ans = new Vertex[cnt];
System.arraycopy(temp, 0, ans, 0, cnt);
@@ -983,7 +993,7 @@ public class DirectedGraph {
AttributeManager<Edge> attm = this.edgeAttributes;
AttributeManager<Edge> copyManager = copy.edgeAttributes();
String[] names = attm.getAttributeNames();
- List<Attribute<Edge>> attrs = new ArrayList<Attribute<Edge>>(names.length);
+ List<Attribute<Edge>> attrs = new ArrayList<>(names.length);
for (String name : names) {
attrs.add(attm.getAttribute(name));
}
@@ -1070,7 +1080,7 @@ public class DirectedGraph {
AttributeManager<Vertex> attm = this.vertexAttributes;
AttributeManager<Vertex> copyManager = copy.vertexAttributes();
String[] names = attm.getAttributeNames();
- List<Attribute<Vertex>> attrs = new ArrayList<Attribute<Vertex>>();
+ List<Attribute<Vertex>> attrs = new ArrayList<>();
for (String name : names) {
attrs.add(attm.getAttribute(name));
@@ -1160,8 +1170,9 @@ public class DirectedGraph {
*/
protected void copyVertex(Vertex node, DirectedGraph other) {
add(node);
- if (other != null)
+ if (other != null) {
copyVertexAttributeValues(node, other);
+ }
}
/**
@@ -1194,14 +1205,15 @@ public class DirectedGraph {
AttributeManager<Edge> aman = other.edgeAttributes();
String vamNames[] = aman.getAttributeNames();
- for (int i = 0; i < vamNames.length; i++) {
- ObjectAttribute<Edge> att = (ObjectAttribute<Edge>) aman.getAttribute(vamNames[i]);
- if (!this.edgeAttributes().hasAttributeNamed(vamNames[i])) {
- this.edgeAttributes().createAttribute(vamNames[i], att.attributeType());
+ for (String vamName : vamNames) {
+ ObjectAttribute<Edge> att = (ObjectAttribute<Edge>) aman.getAttribute(vamName);
+ if (!this.edgeAttributes().hasAttributeNamed(vamName)) {
+ this.edgeAttributes().createAttribute(vamName, att.attributeType());
+ }
+ Object o = other.getEdgeProperty(vamName, e);
+ if (o != null) {
+ this.setEdgeProperty(vamName, newe, o);
}
- Object o = other.getEdgeProperty(vamNames[i], e);
- if (o != null)
- this.setEdgeProperty(vamNames[i], newe, o);
}
}
@@ -1239,14 +1251,15 @@ public class DirectedGraph {
AttributeManager<Vertex> aman = other.vertexAttributes();
String vamNames[] = aman.getAttributeNames();
- for (int i = 0; i < vamNames.length; i++) {
- ObjectAttribute<Vertex> att = (ObjectAttribute<Vertex>) aman.getAttribute(vamNames[i]);
- if (!this.vertexAttributes().hasAttributeNamed(vamNames[i])) {
- this.vertexAttributes().createAttribute(vamNames[i], att.attributeType());
+ for (String vamName : vamNames) {
+ ObjectAttribute<Vertex> att = (ObjectAttribute<Vertex>) aman.getAttribute(vamName);
+ if (!this.vertexAttributes().hasAttributeNamed(vamName)) {
+ this.vertexAttributes().createAttribute(vamName, att.attributeType());
+ }
+ Object o = other.getVertexProperty(vamName, vert);
+ if (o != null) {
+ this.setVertexProperty(vamName, vert, o);
}
- Object o = other.getVertexProperty(vamNames[i], vert);
- if (o != null)
- this.setVertexProperty(vamNames[i], vert, o);
}
}
@@ -1347,7 +1360,7 @@ public class DirectedGraph {
* @return the set of referent objects
*/
public static Set<?> verts2referentSet(Collection<Vertex> verts) {
- Set<Object> s = new HashSet<Object>();
+ Set<Object> s = new HashSet<>();
Iterator<Vertex> vIter = verts.iterator();
while (vIter.hasNext()) {
Vertex vert = vIter.next();
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Dominator.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Dominator.java
index ceb27155fb..09232ff9a8 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Dominator.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Dominator.java
@@ -30,7 +30,7 @@ import ghidra.util.graph.attributes.*;
* titled "Building a Dominance Graph"
*
*/
-
+@Deprecated(forRemoval = true, since = "10.2") // This class is no longer used or tested. Use GraphAlgorithms
public class Dominator extends DirectedGraph //implements Weighted
{
private IntegerAttribute<Vertex> vertexColor;
@@ -95,7 +95,7 @@ public class Dominator extends DirectedGraph //implements Weighted
{
this();
KeyIndexableSet.Iterator it = sw.vertexIterator();
-
+
while(it.hasNext())
{
Vertex next = (Vertex)it.next();
@@ -104,7 +104,7 @@ public class Dominator extends DirectedGraph //implements Weighted
this.setColor(next,white);
this.setType(next, sw.getType(next));
}
-
+
it = sw.edgeIterator();
while(it.hasNext())
{
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Edge.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Edge.java
index faa03c1654..0e581d0ce9 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Edge.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Edge.java
@@ -20,79 +20,71 @@ import ghidra.util.Msg;
/** An Edge joins a pair of vertices.
* The from and to vertex of an edge can not be changed.
*/
-public final class Edge implements KeyedObject, Comparable<Edge>
-{
- private final long key;
- private static final KeyedObjectFactory kof = KeyedObjectFactory.getInstance();
+@Deprecated(since = "10.2")
+public final class Edge implements KeyedObject, Comparable<Edge> {
+ private final long key;
+ private static final KeyedObjectFactory kof = KeyedObjectFactory.getInstance();
// private static long nextKey = 0;
- private final Vertex from;
- private final Vertex to;
+ private final Vertex from;
+ private final Vertex to;
- /** @param from The from or parent vertex.
- * @param to The to or child vertex.
- */
- public Edge( Vertex from, Vertex to )
- {
- if( from == null || to == null )
- {
- Msg.error(this, "Bad edge");
- }
- this.key = getNextKey();
- this.from = from;
- this.to = to;
- }
-
- /** Returns next key **/
- private static synchronized long getNextKey() {
- return kof.getNextAvailableKey();
- }
+ /** @param from The from or parent vertex.
+ * @param to The to or child vertex.
+ */
+ public Edge(Vertex from, Vertex to) {
+ if (from == null || to == null) {
+ Msg.error(this, "Bad edge");
+ }
+ this.key = getNextKey();
+ this.from = from;
+ this.to = to;
+ }
- /** Returns from vertex. */
- public Vertex from()
- {
- return this.from;
- }
+ /** Returns next key **/
+ private static synchronized long getNextKey() {
+ return kof.getNextAvailableKey();
+ }
- /** Returns to vertex. */
- public Vertex to()
- {
- return this.to;
- }
+ /** Returns from vertex. */
+ public Vertex from() {
+ return this.from;
+ }
- /** Returns the key of this edge. */
- public long key()
- {
- return this.key;
- }
+ /** Returns to vertex. */
+ public Vertex to() {
+ return this.to;
+ }
- /** Compare one edge to another. Based on time of creation. */
- public int compareTo( Edge edge )
- {
- if( this.key() < edge.key() )
- {
- return -1;
- }
- else if( this.key() > edge.key() )
- {
- return +1;
- }
- return 0;
- }
+ /** Returns the key of this edge. */
+ @Override
+ public long key() {
+ return this.key;
+ }
+
+ /** Compare one edge to another. Based on time of creation. */
+ @Override
+ public int compareTo(Edge edge) {
+ if (this.key() < edge.key()) {
+ return -1;
+ }
+ else if (this.key() > edge.key()) {
+ return +1;
+ }
+ return 0;
+ }
+
+ /** Overides equals method by comparing keys.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Edge) {
+ return key == ((Edge) obj).key();
+ }
+ return false;
+ }
- /** Overides equals method by comparing keys.
- */
- @Override
-public boolean equals( Object obj )
- {
- if( obj instanceof Edge )
- {
- return key == ((Edge)obj).key();
- }
- return false;
- }
-
- @Override
+ @Override
public int hashCode() {
- return (int) key;
+ return (int) key;
}
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/EdgeSet.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/EdgeSet.java
index b34ddf6985..d58b9f1935 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/EdgeSet.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/EdgeSet.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,417 +15,374 @@
*/
package ghidra.util.graph;
-import ghidra.util.exception.NoValueException;
-
import java.util.*;
+import ghidra.util.exception.NoValueException;
/** Container class for a set of edges (ghidra.util.graph.Edge).
*
*
*/
+@Deprecated(since = "10.2")
class EdgeSet implements KeyIndexableSet<Edge> {
- private final DirectedGraph parentGraph;
- private long modificationNumber;
- private int capacity;
- private int nextIndex;
- private AddableLongIntHashtable edgeIndices;
- private Edge [] edges;
- private Edge [] previousEdgeWithSameFrom;
- private Edge [] previousEdgeWithSameTo;
- private Edge [] nextEdgeWithSameFrom;
- private Edge [] nextEdgeWithSameTo;
-
-/** Constructor
- * @param parent The DirectedGraph that this EdgeSet belongs to.
- * @param capacity The initial number of edges this edge set can have
- * without growing.
- */
- EdgeSet( DirectedGraph parent, int capacity)
- {
- if( capacity < 10 ) capacity = 10;
- this.parentGraph = parent;
- this.modificationNumber = 0;
- this.capacity = capacity;
- this.nextIndex = 0;
- edgeIndices = new AddableLongIntHashtable( capacity );
- edges = new Edge[capacity];
- previousEdgeWithSameFrom = new Edge[capacity];
- previousEdgeWithSameTo = new Edge[capacity];
- nextEdgeWithSameFrom = new Edge[capacity];
- nextEdgeWithSameTo = new Edge[capacity];
- }
-
- /** Returns the edge at the specified index in the internal arrays. */
- Edge getByIndex( int index )
- {
- return edges[index];
- }
-
- /** Removes an edge from this EdgeSet. Returns true if and only if the
- * edge was in the EdgeSet and was sucessfully removed.
- */
- public boolean remove( Edge e )
- {
- if( e == null )
- {
- return false;
- }
- VertexSet vertices = parentGraph.vertices();
- Edge oldNextEdgeWithSameFrom = getNextEdgeWithSameFrom( e );
- Edge oldNextEdgeWithSameTo = getNextEdgeWithSameTo( e );
- Edge oldPreviousEdgeWithSameFrom = getPreviousEdgeWithSameFrom( e);
- Edge oldPreviousEdgeWithSameTo = getPreviousEdgeWithSameTo( e );
- Vertex from = e.from();
- Vertex to = e.to();
- Edge firstOutgoingEdgeOfFrom = vertices.getFirstOutgoingEdge( from );
- Edge firstIncomingEdgeOfTo = vertices.getFirstIncomingEdge( to );
- Edge lastOutgoingEdgeOfFrom = vertices.getLastOutgoingEdge( from );
- Edge lastIncomingEdgeOfTo = vertices.getLastIncomingEdge( to );
-
- if( e.equals( firstOutgoingEdgeOfFrom ) )
- {
- vertices.setFirstOutgoingEdge( from, oldNextEdgeWithSameFrom );
- }
-
- if( e.equals( lastOutgoingEdgeOfFrom ) )
- {
- vertices.setLastOutgoingEdge( from, oldPreviousEdgeWithSameFrom );
- }
-
- if( e.equals( firstIncomingEdgeOfTo ) )
- {
- vertices.setFirstIncomingEdge( to, oldNextEdgeWithSameTo );
- }
-
- if( e.equals( lastIncomingEdgeOfTo ) )
- {
- vertices.setLastIncomingEdge( to, oldPreviousEdgeWithSameTo );
- }
-
- if( oldNextEdgeWithSameFrom != null )
- {
- setPreviousEdgeWithSameFrom(oldNextEdgeWithSameFrom, oldPreviousEdgeWithSameFrom);
- }
-
- if( oldPreviousEdgeWithSameFrom != null )
- {
- setNextEdgeWithSameFrom(oldPreviousEdgeWithSameFrom, oldNextEdgeWithSameFrom);
- }
-
- if( oldNextEdgeWithSameTo != null )
- {
- setPreviousEdgeWithSameTo(oldNextEdgeWithSameTo,oldPreviousEdgeWithSameTo);
- }
-
- if( oldPreviousEdgeWithSameTo != null )
- {
- setNextEdgeWithSameTo(oldPreviousEdgeWithSameTo, oldNextEdgeWithSameTo);
- }
-
- setPreviousEdgeWithSameFrom(e , null );
- setNextEdgeWithSameFrom( e, null );
- setPreviousEdgeWithSameTo( e, null );
- setNextEdgeWithSameTo( e, null );
-
- try{
- int index = edgeIndices.get( e.key() );
- edges[index] = null;
- edgeIndices.remove( e.key() );
- modificationNumber++;
- return true;
- }catch( NoValueException exc ){
- //do nothing
- }
- return false;
- }
-
-
- /** Adds an edge to the graph. If either endpoint is not in the graph add it.
- * If the edge is already in the graph return false and do nothing.
- * @return true if and only if the edge was sucessfully added.
- */
- public boolean add( Edge e )
- {
- if( contains(e) )
- {
- return false;
- }
- else if( nextIndex >= capacity )
- {
- grow();
- }
-
- edges[nextIndex] = e;
- edgeIndices.add( e.key(), nextIndex++ );
- VertexSet vertices = parentGraph.vertices();
- Vertex from = e.from();
- Vertex to = e.to();
- if( !vertices.contains( from ) )
- {
- vertices.add( from );
- }
- if( !vertices.contains( to ) )
- {
- vertices.add( to );
- }
-
- Edge oldLastOutgoingEdge = vertices.getLastOutgoingEdge( from );
- if( oldLastOutgoingEdge == null )
- {
- vertices.setFirstOutgoingEdge( from, e );
- vertices.setLastOutgoingEdge( from, e );
- }
- else
- {
- vertices.setLastOutgoingEdge( from, e );
- setNextEdgeWithSameFrom( oldLastOutgoingEdge, e );
- setPreviousEdgeWithSameFrom( e, oldLastOutgoingEdge );
- }
-
- Edge oldLastIncomingEdge = vertices.getLastIncomingEdge( to );
- if( oldLastIncomingEdge == null )
- {
- vertices.setFirstIncomingEdge( to, e );
- vertices.setLastIncomingEdge( to, e );
- }
- else
- {
- vertices.setLastIncomingEdge( to, e );
- setNextEdgeWithSameTo( oldLastIncomingEdge, e );
- setPreviousEdgeWithSameTo( e, oldLastIncomingEdge );
- }
- modificationNumber++;
- return true;
-
- }
-
- /** Return true if and only if the edge is contained in this EdgeSet. */
- public boolean contains( Edge edge )
- {
- return edgeIndices.contains( edge.key() );
- }
-
- /** Returns the internal index of the given edge within this edge set.
- * Throws a class cast exception if the object is not an edge. */
- int index( Edge e )
- {
- try{
- return edgeIndices.get( e.key() );
- }catch( NoValueException exc ){
- return -1;
- }
- }
-
- /** Returns the next edge having the same 'from' if it exists. Otherwise
- returns null.
- */
- Edge getNextEdgeWithSameFrom( Edge e )
- {
- int indexOfEdge = index(e);
- if( indexOfEdge >= 0 )
- {
- return nextEdgeWithSameFrom[ indexOfEdge ];
- }
- return null;
- }
-
- /** Returns next edge having the same 'to' if it exists. Otherwise returns
- null.
- */
- Edge getNextEdgeWithSameTo( Edge e )
- {
- int indexOfEdge = index( e );
- if( indexOfEdge >= 0 )
- {
- return nextEdgeWithSameTo[ indexOfEdge ];
- }
- return null;
- }
-
- /** Returns the previous edge having the same 'from' if it exists. Otherwise
- returns null.
- */
- Edge getPreviousEdgeWithSameFrom( Edge e )
- {
- int indexOfEdge = index( e );
- if( indexOfEdge >= 0 )
- {
- return previousEdgeWithSameFrom[ indexOfEdge ];
- }
- return null;
- }
-
- /** Returns previous edge having the same 'to' if it exists. Otherwise returns
- null.
- */
- Edge getPreviousEdgeWithSameTo( Edge e )
- {
- int indexOfEdge = index( e );
- if( indexOfEdge >= 0 )
- {
- return previousEdgeWithSameTo[ indexOfEdge ];
- }
- return null;
- }
+ private final DirectedGraph parentGraph;
+ private long modificationNumber;
+ private int capacity;
+ private int nextIndex;
+ private AddableLongIntHashtable edgeIndices;
+ private Edge[] edges;
+ private Edge[] previousEdgeWithSameFrom;
+ private Edge[] previousEdgeWithSameTo;
+ private Edge[] nextEdgeWithSameFrom;
+ private Edge[] nextEdgeWithSameTo;
+
+ /** Constructor
+ * @param parent The DirectedGraph that this EdgeSet belongs to.
+ * @param capacity The initial number of edges this edge set can have
+ * without growing.
+ */
+ EdgeSet(DirectedGraph parent, int capacity) {
+ if (capacity < 10) {
+ capacity = 10;
+ }
+ this.parentGraph = parent;
+ this.modificationNumber = 0;
+ this.capacity = capacity;
+ this.nextIndex = 0;
+ edgeIndices = new AddableLongIntHashtable(capacity);
+ edges = new Edge[capacity];
+ previousEdgeWithSameFrom = new Edge[capacity];
+ previousEdgeWithSameTo = new Edge[capacity];
+ nextEdgeWithSameFrom = new Edge[capacity];
+ nextEdgeWithSameTo = new Edge[capacity];
+ }
+
+ /** Returns the edge at the specified index in the internal arrays. */
+ Edge getByIndex(int index) {
+ return edges[index];
+ }
+
+ /** Removes an edge from this EdgeSet. Returns true if and only if the
+ * edge was in the EdgeSet and was sucessfully removed.
+ */
+ @Override
+ public boolean remove(Edge e) {
+ if (e == null) {
+ return false;
+ }
+ VertexSet vertices = parentGraph.vertices();
+ Edge oldNextEdgeWithSameFrom = getNextEdgeWithSameFrom(e);
+ Edge oldNextEdgeWithSameTo = getNextEdgeWithSameTo(e);
+ Edge oldPreviousEdgeWithSameFrom = getPreviousEdgeWithSameFrom(e);
+ Edge oldPreviousEdgeWithSameTo = getPreviousEdgeWithSameTo(e);
+ Vertex from = e.from();
+ Vertex to = e.to();
+ Edge firstOutgoingEdgeOfFrom = vertices.getFirstOutgoingEdge(from);
+ Edge firstIncomingEdgeOfTo = vertices.getFirstIncomingEdge(to);
+ Edge lastOutgoingEdgeOfFrom = vertices.getLastOutgoingEdge(from);
+ Edge lastIncomingEdgeOfTo = vertices.getLastIncomingEdge(to);
+
+ if (e.equals(firstOutgoingEdgeOfFrom)) {
+ vertices.setFirstOutgoingEdge(from, oldNextEdgeWithSameFrom);
+ }
+
+ if (e.equals(lastOutgoingEdgeOfFrom)) {
+ vertices.setLastOutgoingEdge(from, oldPreviousEdgeWithSameFrom);
+ }
+
+ if (e.equals(firstIncomingEdgeOfTo)) {
+ vertices.setFirstIncomingEdge(to, oldNextEdgeWithSameTo);
+ }
+
+ if (e.equals(lastIncomingEdgeOfTo)) {
+ vertices.setLastIncomingEdge(to, oldPreviousEdgeWithSameTo);
+ }
+
+ if (oldNextEdgeWithSameFrom != null) {
+ setPreviousEdgeWithSameFrom(oldNextEdgeWithSameFrom, oldPreviousEdgeWithSameFrom);
+ }
+
+ if (oldPreviousEdgeWithSameFrom != null) {
+ setNextEdgeWithSameFrom(oldPreviousEdgeWithSameFrom, oldNextEdgeWithSameFrom);
+ }
+
+ if (oldNextEdgeWithSameTo != null) {
+ setPreviousEdgeWithSameTo(oldNextEdgeWithSameTo, oldPreviousEdgeWithSameTo);
+ }
+
+ if (oldPreviousEdgeWithSameTo != null) {
+ setNextEdgeWithSameTo(oldPreviousEdgeWithSameTo, oldNextEdgeWithSameTo);
+ }
+
+ setPreviousEdgeWithSameFrom(e, null);
+ setNextEdgeWithSameFrom(e, null);
+ setPreviousEdgeWithSameTo(e, null);
+ setNextEdgeWithSameTo(e, null);
+
+ try {
+ int index = edgeIndices.get(e.key());
+ edges[index] = null;
+ edgeIndices.remove(e.key());
+ modificationNumber++;
+ return true;
+ }
+ catch (NoValueException exc) {
+ //do nothing
+ }
+ return false;
+ }
+
+ /** Adds an edge to the graph. If either endpoint is not in the graph add it.
+ * If the edge is already in the graph return false and do nothing.
+ * @return true if and only if the edge was sucessfully added.
+ */
+ @Override
+ public boolean add(Edge e) {
+ if (contains(e)) {
+ return false;
+ }
+ else if (nextIndex >= capacity) {
+ grow();
+ }
+
+ edges[nextIndex] = e;
+ edgeIndices.add(e.key(), nextIndex++);
+ VertexSet vertices = parentGraph.vertices();
+ Vertex from = e.from();
+ Vertex to = e.to();
+ if (!vertices.contains(from)) {
+ vertices.add(from);
+ }
+ if (!vertices.contains(to)) {
+ vertices.add(to);
+ }
+
+ Edge oldLastOutgoingEdge = vertices.getLastOutgoingEdge(from);
+ if (oldLastOutgoingEdge == null) {
+ vertices.setFirstOutgoingEdge(from, e);
+ vertices.setLastOutgoingEdge(from, e);
+ }
+ else {
+ vertices.setLastOutgoingEdge(from, e);
+ setNextEdgeWithSameFrom(oldLastOutgoingEdge, e);
+ setPreviousEdgeWithSameFrom(e, oldLastOutgoingEdge);
+ }
+
+ Edge oldLastIncomingEdge = vertices.getLastIncomingEdge(to);
+ if (oldLastIncomingEdge == null) {
+ vertices.setFirstIncomingEdge(to, e);
+ vertices.setLastIncomingEdge(to, e);
+ }
+ else {
+ vertices.setLastIncomingEdge(to, e);
+ setNextEdgeWithSameTo(oldLastIncomingEdge, e);
+ setPreviousEdgeWithSameTo(e, oldLastIncomingEdge);
+ }
+ modificationNumber++;
+ return true;
+
+ }
+
+ /** Return true if and only if the edge is contained in this EdgeSet. */
+ @Override
+ public boolean contains(Edge edge) {
+ return edgeIndices.contains(edge.key());
+ }
+
+ /** Returns the internal index of the given edge within this edge set.
+ * Throws a class cast exception if the object is not an edge. */
+ int index(Edge e) {
+ try {
+ return edgeIndices.get(e.key());
+ }
+ catch (NoValueException exc) {
+ return -1;
+ }
+ }
+
+ /** Returns the next edge having the same 'from' if it exists. Otherwise
+ returns null.
+ */
+ Edge getNextEdgeWithSameFrom(Edge e) {
+ int indexOfEdge = index(e);
+ if (indexOfEdge >= 0) {
+ return nextEdgeWithSameFrom[indexOfEdge];
+ }
+ return null;
+ }
+
+ /** Returns next edge having the same 'to' if it exists. Otherwise returns
+ null.
+ */
+ Edge getNextEdgeWithSameTo(Edge e) {
+ int indexOfEdge = index(e);
+ if (indexOfEdge >= 0) {
+ return nextEdgeWithSameTo[indexOfEdge];
+ }
+ return null;
+ }
+
+ /** Returns the previous edge having the same 'from' if it exists. Otherwise
+ returns null.
+ */
+ Edge getPreviousEdgeWithSameFrom(Edge e) {
+ int indexOfEdge = index(e);
+ if (indexOfEdge >= 0) {
+ return previousEdgeWithSameFrom[indexOfEdge];
+ }
+ return null;
+ }
+
+ /** Returns previous edge having the same 'to' if it exists. Otherwise returns
+ null.
+ */
+ Edge getPreviousEdgeWithSameTo(Edge e) {
+ int indexOfEdge = index(e);
+ if (indexOfEdge >= 0) {
+ return previousEdgeWithSameTo[indexOfEdge];
+ }
+ return null;
+ }
/** Helper method for maintaining internal data structures. */
- private void setNextEdgeWithSameFrom(Edge e, Edge nextEdge)
- {
- nextEdgeWithSameFrom[ index( e ) ] = nextEdge;
- }
-
- /** Helper method for maintaining internal data structures. */
- private void setNextEdgeWithSameTo(Edge e, Edge nextEdge)
- {
- nextEdgeWithSameTo[ index( e ) ] = nextEdge;
- }
-
+ private void setNextEdgeWithSameFrom(Edge e, Edge nextEdge) {
+ nextEdgeWithSameFrom[index(e)] = nextEdge;
+ }
/** Helper method for maintaining internal data structures. */
- private void setPreviousEdgeWithSameFrom(Edge e, Edge previousEdge)
- {
- previousEdgeWithSameFrom[ index( e ) ] = previousEdge;
- }
+ private void setNextEdgeWithSameTo(Edge e, Edge nextEdge) {
+ nextEdgeWithSameTo[index(e)] = nextEdge;
+ }
+ /** Helper method for maintaining internal data structures. */
+ private void setPreviousEdgeWithSameFrom(Edge e, Edge previousEdge) {
+ previousEdgeWithSameFrom[index(e)] = previousEdge;
+ }
/** Helper method for maintaining internal data structures. */
- private void setPreviousEdgeWithSameTo(Edge e, Edge previousEdge)
- {
- previousEdgeWithSameTo[ index( e ) ] = previousEdge;
- }
-
-
- /** Returns the current number of edges within this edge set. */
- public int size()
- {
- return this.edgeIndices.size();
- }
-
- /** Empties out the edge set while leaving the capacity alone. Much faster
- than removing the edges one by one.
- */
- public void clear()
- {
- if( size() > 0 )
- {
- edgeIndices.removeAll();
- for( int i=0; i< capacity; i++ )
- {
- edges[i] = null;
- previousEdgeWithSameFrom[i] = null;
- previousEdgeWithSameTo[i] = null;
- nextEdgeWithSameFrom[i] = null;
- nextEdgeWithSameTo[i] = null;
- }
- }
- nextIndex = 0;
- modificationNumber++;
- }
-
- /** Returns the number of edges this edge set can hold without growing. */
- public int capacity()
- {
- return this.capacity;
- }
-
- /** Either compacts the edge set by removing vacant positions if there are
- many or grows the edge set so that there is additional space.
- */
- void grow()
- {
- int newCapacity = (int)Math.round( this.size()* 1.7) + 7;
- nextIndex = 0;
- modificationNumber++;
- if( (this.size()*13) > (capacity*9) )
- {
- Edge [] newEdges = new Edge[newCapacity];
- Edge [] newPreviousEdgeWithSameFrom = new Edge[newCapacity];
- Edge [] newPreviousEdgeWithSameTo = new Edge[newCapacity];
- Edge [] newNextEdgeWithSameFrom = new Edge[newCapacity];
- Edge [] newNextEdgeWithSameTo = new Edge[newCapacity];
-
- for( int i=0; i<capacity; i++ )
- {
- if( edges[i] != null )
- {
- newEdges[nextIndex] = edges[i];
- newPreviousEdgeWithSameFrom[nextIndex] = previousEdgeWithSameFrom[i];
- newPreviousEdgeWithSameTo[nextIndex] = previousEdgeWithSameTo[i];
- newNextEdgeWithSameFrom[nextIndex] = nextEdgeWithSameFrom[i];
- newNextEdgeWithSameTo[nextIndex] = nextEdgeWithSameTo[i];
- this.edgeIndices.remove( edges[i].key());
- this.edgeIndices.put( edges[i].key(), nextIndex );
- nextIndex++;
- }
- }
- capacity = newCapacity;
- edges = newEdges;
- previousEdgeWithSameFrom = newPreviousEdgeWithSameFrom;
- previousEdgeWithSameTo = newPreviousEdgeWithSameTo;
- nextEdgeWithSameFrom = newNextEdgeWithSameFrom;
- nextEdgeWithSameTo = newNextEdgeWithSameTo;
- }
- else // just tighten
- {
- tighten();
- }
- }
-
- private void tighten()
- {
- nextIndex = 0;
- for( int i=0; i<capacity; i++ )
- {
- if( edges[i] != null )
- {
- if( i > nextIndex )
- {
- edges[nextIndex] = edges[i];
- previousEdgeWithSameFrom[nextIndex] = previousEdgeWithSameFrom[i];
- previousEdgeWithSameTo[nextIndex] = previousEdgeWithSameTo[i];
- nextEdgeWithSameFrom[nextIndex] = nextEdgeWithSameFrom[i];
- nextEdgeWithSameTo[nextIndex] = nextEdgeWithSameTo[i];
- edgeIndices.remove( edges[i].key());
- edgeIndices.put( edges[i].key(), nextIndex );
- edges[i] = null;
- previousEdgeWithSameFrom[i] = null;
- previousEdgeWithSameTo[i] = null;
- nextEdgeWithSameFrom[i] = null;
- nextEdgeWithSameTo[i] = null;
- }
- nextIndex++;
- }
- }
- }
-
- /** Returns an iterator for this EdgeSet. */
- public GraphIterator<Edge> iterator()
- {
- return new EdgeSetIterator();
- }
-
- /** Used to test if edges have been added or removed from this edge set. */
- public long getModificationNumber()
- {
- return this.modificationNumber;
- }
-
- /* (non-Javadoc)
- * @see ghidra.util.graph.KeyIndexableSet#getKeyedObject(long)
- */
- public Edge getKeyedObject(long key)
- {
- if (edgeIndices.contains(key)) {
- try {
- return edges[edgeIndices.get(key)];
- } catch (Exception e) {
- return null;
- }
- }
- return null;
- }
-
+ private void setPreviousEdgeWithSameTo(Edge e, Edge previousEdge) {
+ previousEdgeWithSameTo[index(e)] = previousEdge;
+ }
+
+ /** Returns the current number of edges within this edge set. */
+ @Override
+ public int size() {
+ return this.edgeIndices.size();
+ }
+
+ /** Empties out the edge set while leaving the capacity alone. Much faster
+ than removing the edges one by one.
+ */
+ public void clear() {
+ if (size() > 0) {
+ edgeIndices.removeAll();
+ for (int i = 0; i < capacity; i++) {
+ edges[i] = null;
+ previousEdgeWithSameFrom[i] = null;
+ previousEdgeWithSameTo[i] = null;
+ nextEdgeWithSameFrom[i] = null;
+ nextEdgeWithSameTo[i] = null;
+ }
+ }
+ nextIndex = 0;
+ modificationNumber++;
+ }
+
+ /** Returns the number of edges this edge set can hold without growing. */
+ @Override
+ public int capacity() {
+ return this.capacity;
+ }
+
+ /** Either compacts the edge set by removing vacant positions if there are
+ many or grows the edge set so that there is additional space.
+ */
+ void grow() {
+ int newCapacity = (int) Math.round(this.size() * 1.7) + 7;
+ nextIndex = 0;
+ modificationNumber++;
+ if ((this.size() * 13) > (capacity * 9)) {
+ Edge[] newEdges = new Edge[newCapacity];
+ Edge[] newPreviousEdgeWithSameFrom = new Edge[newCapacity];
+ Edge[] newPreviousEdgeWithSameTo = new Edge[newCapacity];
+ Edge[] newNextEdgeWithSameFrom = new Edge[newCapacity];
+ Edge[] newNextEdgeWithSameTo = new Edge[newCapacity];
+
+ for (int i = 0; i < capacity; i++) {
+ if (edges[i] != null) {
+ newEdges[nextIndex] = edges[i];
+ newPreviousEdgeWithSameFrom[nextIndex] = previousEdgeWithSameFrom[i];
+ newPreviousEdgeWithSameTo[nextIndex] = previousEdgeWithSameTo[i];
+ newNextEdgeWithSameFrom[nextIndex] = nextEdgeWithSameFrom[i];
+ newNextEdgeWithSameTo[nextIndex] = nextEdgeWithSameTo[i];
+ this.edgeIndices.remove(edges[i].key());
+ this.edgeIndices.put(edges[i].key(), nextIndex);
+ nextIndex++;
+ }
+ }
+ capacity = newCapacity;
+ edges = newEdges;
+ previousEdgeWithSameFrom = newPreviousEdgeWithSameFrom;
+ previousEdgeWithSameTo = newPreviousEdgeWithSameTo;
+ nextEdgeWithSameFrom = newNextEdgeWithSameFrom;
+ nextEdgeWithSameTo = newNextEdgeWithSameTo;
+ }
+ else // just tighten
+ {
+ tighten();
+ }
+ }
+
+ private void tighten() {
+ nextIndex = 0;
+ for (int i = 0; i < capacity; i++) {
+ if (edges[i] != null) {
+ if (i > nextIndex) {
+ edges[nextIndex] = edges[i];
+ previousEdgeWithSameFrom[nextIndex] = previousEdgeWithSameFrom[i];
+ previousEdgeWithSameTo[nextIndex] = previousEdgeWithSameTo[i];
+ nextEdgeWithSameFrom[nextIndex] = nextEdgeWithSameFrom[i];
+ nextEdgeWithSameTo[nextIndex] = nextEdgeWithSameTo[i];
+ edgeIndices.remove(edges[i].key());
+ edgeIndices.put(edges[i].key(), nextIndex);
+ edges[i] = null;
+ previousEdgeWithSameFrom[i] = null;
+ previousEdgeWithSameTo[i] = null;
+ nextEdgeWithSameFrom[i] = null;
+ nextEdgeWithSameTo[i] = null;
+ }
+ nextIndex++;
+ }
+ }
+ }
+
+ /** Returns an iterator for this EdgeSet. */
+ @Override
+ public GraphIterator<Edge> iterator() {
+ return new EdgeSetIterator();
+ }
+
+ /** Used to test if edges have been added or removed from this edge set. */
+ @Override
+ public long getModificationNumber() {
+ return this.modificationNumber;
+ }
+
+ /* (non-Javadoc)
+ * @see ghidra.util.graph.KeyIndexableSet#getKeyedObject(long)
+ */
+ @Override
+ public Edge getKeyedObject(long key) {
+ if (edgeIndices.contains(key)) {
+ try {
+ return edges[edgeIndices.get(key)];
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+ return null;
+ }
// /** Used for debugging. */
// void verbosePrint()
@@ -441,115 +397,99 @@ class EdgeSet implements KeyIndexableSet<Edge> {
// }
// }
- /** Get the edges in this EdgeSet as a java.util.Set. */
- public Set<Edge> toSet()
- {
- GraphIterator<Edge> i = this.iterator();
- Set<Edge> s = new HashSet<Edge>( this.size() );
- while( i.hasNext() )
- {
- s.add( i.next() );
- }
- return s;
- }
+ /** Get the edges in this EdgeSet as a java.util.Set. */
+ public Set<Edge> toSet() {
+ GraphIterator<Edge> i = this.iterator();
+ Set<Edge> s = new HashSet<>(this.size());
+ while (i.hasNext()) {
+ s.add(i.next());
+ }
+ return s;
+ }
/** @return array of Edges contained in this EdgeSet */
- public Edge[] toArray()
- {
- Edge[] theEdges = new Edge[this.size()];
- int i=0, cnt = 0;
- int done = this.size();
- while( cnt < done )
- {
- if( edges[i] != null )
- {
- theEdges[cnt++] = edges[i];
- }
- i++;
- }
- return theEdges;
- }
-
-
-
- /** EdgeSetIterator uses the hasNext()/next() paradigm. Throws
- a ConcurrentModificationException if any addition or deletions to
- the backing EdgeSet are made except through the iterator's own methods.
- */
- private class EdgeSetIterator implements GraphIterator<Edge>
- {
- private int currentPosition;
- private int nextPosition;
- private long edgeSetModificationNumber;
-
- /** Constructor */
- public EdgeSetIterator()
- {
- currentPosition = -1;
- nextPosition = -1;
- //CompactEdgeSet.edgeSet = (CompactEdgeSet)parentGraph.edges();
- this.edgeSetModificationNumber = getModificationNumber();
- getNextPosition();
- }
-
- private void getNextPosition()
- {
- nextPosition++;
- while( (nextPosition < capacity()) && ( edges[nextPosition] == null ))
- {
- nextPosition++;
- }
- }
-
- /** @return true if and only if a call to next() will return a valid edge.
- * @throws ConcurrentModificationException
- */
- public boolean hasNext() throws ConcurrentModificationException
- {
- if( edgeSetModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Edge Set Modified");
- }
- if( nextPosition < capacity() )
- {
- return true;
- }
- return false;
- }
-
- /** @return the next edge.
- * @throws ConcurrentModificationException
- * @throws NoSuchElementException if there is no next edge.
- */
- public Edge next() throws ConcurrentModificationException
- {
- if( edgeSetModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Edge Set Modified");
- }
- if( nextPosition < capacity() )
- {
- currentPosition = nextPosition;
- getNextPosition();
- return edges[currentPosition];
- }
- throw new NoSuchElementException();
- }
-
- /** Removes the edge returned by the most recent call to next(). */
- public boolean remove() throws ConcurrentModificationException
- {
- boolean removed;
- if( edgeSetModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Edge Set Modified");
- }
- removed = EdgeSet.this.remove( edges[currentPosition] );
- edgeSetModificationNumber = getModificationNumber();
- return removed;
- }
+ @Override
+ public Edge[] toArray() {
+ Edge[] theEdges = new Edge[this.size()];
+ int i = 0, cnt = 0;
+ int done = this.size();
+ while (cnt < done) {
+ if (edges[i] != null) {
+ theEdges[cnt++] = edges[i];
+ }
+ i++;
+ }
+ return theEdges;
+ }
+
+ /** EdgeSetIterator uses the hasNext()/next() paradigm. Throws
+ a ConcurrentModificationException if any addition or deletions to
+ the backing EdgeSet are made except through the iterator's own methods.
+ */
+ private class EdgeSetIterator implements GraphIterator<Edge> {
+ private int currentPosition;
+ private int nextPosition;
+ private long edgeSetModificationNumber;
+
+ /** Constructor */
+ public EdgeSetIterator() {
+ currentPosition = -1;
+ nextPosition = -1;
+ //CompactEdgeSet.edgeSet = (CompactEdgeSet)parentGraph.edges();
+ this.edgeSetModificationNumber = getModificationNumber();
+ getNextPosition();
+ }
+
+ private void getNextPosition() {
+ nextPosition++;
+ while ((nextPosition < capacity()) && (edges[nextPosition] == null)) {
+ nextPosition++;
+ }
+ }
+
+ /** @return true if and only if a call to next() will return a valid edge.
+ * @throws ConcurrentModificationException
+ */
+ @Override
+ public boolean hasNext() throws ConcurrentModificationException {
+ if (edgeSetModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Edge Set Modified");
+ }
+ if (nextPosition < capacity()) {
+ return true;
+ }
+ return false;
+ }
+
+ /** @return the next edge.
+ * @throws ConcurrentModificationException
+ * @throws NoSuchElementException if there is no next edge.
+ */
+ @Override
+ public Edge next() throws ConcurrentModificationException {
+ if (edgeSetModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Edge Set Modified");
+ }
+ if (nextPosition < capacity()) {
+ currentPosition = nextPosition;
+ getNextPosition();
+ return edges[currentPosition];
+ }
+ throw new NoSuchElementException();
+ }
+
+ /** Removes the edge returned by the most recent call to next(). */
+ @Override
+ public boolean remove() throws ConcurrentModificationException {
+ boolean removed;
+ if (edgeSetModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Edge Set Modified");
+ }
+ removed = EdgeSet.this.remove(edges[currentPosition]);
+ edgeSetModificationNumber = getModificationNumber();
+ return removed;
+ }
+
+ }
}
-
-}
-
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/GraphIterator.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/GraphIterator.java
index c25348e723..1cc3496a8a 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/GraphIterator.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/GraphIterator.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,18 +22,19 @@ import java.util.ConcurrentModificationException;
*
*
*/
+@Deprecated(since = "10.2")
public interface GraphIterator<T extends KeyedObject> {
/** Return true if the iterator has more elements */
public boolean hasNext();
-
+
/** Returns next element in the iteration.
* @throws ConcurrentModificationException if the backing set
* has been modified since the iterator was created.
*/
public T next() throws ConcurrentModificationException;
-
+
/** Removes the object from the backing set safely */
- public boolean remove();
+ public boolean remove();
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyIndexableSet.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyIndexableSet.java
index 40ba102a62..bb12a2e031 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyIndexableSet.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyIndexableSet.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,56 +15,56 @@
*/
package ghidra.util.graph;
-
/** Interface for sets of graph objects which have keys such as vertices
* and edges.
*
*
*/
+@Deprecated(since = "10.2")
public interface KeyIndexableSet<T extends KeyedObject> {
/** The modification number is a counter for the number of changes
* the KeyIndexableSet has undergone since its creation.
*/
- public long getModificationNumber();
-
- /** Returns the number of KeyedObjects in this KeyIndexableSet */
- public int size();
-
- /** Returns the number of KeyedObjects this KeyIndexableSet can
- * hold without growing.
- */
- public int capacity();
-
- /** Adds a KeyedObject to this KeyIndexableSet. The set will increase
- * in capacity if needed.
- * @return true if the KeyedObject was successfully added. Returns false
- * if the KeyedObject is null or already in the KeyIndexableSet or addition
- * fails for some other reason.
- */
- public boolean add( T o );
-
- /** Remove a KeyedObject from this KeyIndexableSet.
- * @return true if the KeyedObject was sucessfully removed. Returns false
- * if the KeyedObject was not in the KeyIndexablrSet.
- */
- public boolean remove( T o );
-
- /** Returns true if this KeyIndexableSet contains the specified KeyedObject.
- */
- public boolean contains( T o );
-
- /** Returns an iterator for this KeyIndexableSet which uses the
- * hasNext()/next() style. See GraphIterator. */
- public GraphIterator<T> iterator();
+ public long getModificationNumber();
+
+ /** Returns the number of KeyedObjects in this KeyIndexableSet */
+ public int size();
+
+ /** Returns the number of KeyedObjects this KeyIndexableSet can
+ * hold without growing.
+ */
+ public int capacity();
+
+ /** Adds a KeyedObject to this KeyIndexableSet. The set will increase
+ * in capacity if needed.
+ * @return true if the KeyedObject was successfully added. Returns false
+ * if the KeyedObject is null or already in the KeyIndexableSet or addition
+ * fails for some other reason.
+ */
+ public boolean add(T o);
+
+ /** Remove a KeyedObject from this KeyIndexableSet.
+ * @return true if the KeyedObject was sucessfully removed. Returns false
+ * if the KeyedObject was not in the KeyIndexablrSet.
+ */
+ public boolean remove(T o);
+
+ /** Returns true if this KeyIndexableSet contains the specified KeyedObject.
+ */
+ public boolean contains(T o);
+
+ /** Returns an iterator for this KeyIndexableSet which uses the
+ * hasNext()/next() style. See GraphIterator. */
+ public GraphIterator<T> iterator();
/** Returns the elements of this KeyIndexableSet as an array of
* KeyedObjects.
*/
- public T[] toArray();
-
- /** Returns the KeyedObject with the specified key in this KeyIndexableSet.
- * Returns null if the Set contains no object with that key.
- */
- public T getKeyedObject( long key);
+ public T[] toArray();
+
+ /** Returns the KeyedObject with the specified key in this KeyIndexableSet.
+ * Returns null if the Set contains no object with that key.
+ */
+ public T getKeyedObject(long key);
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObject.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObject.java
index 24e42086b4..1db7032a21 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObject.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObject.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +18,8 @@ package ghidra.util.graph;
/** The KeyedObject class is used as a base class for objects which have keys.
* Some specific examples of KeyedObject are Vertex and Edge.
*/
-public interface KeyedObject
-{
- /** Returns the key for this KeyedObject. */
- public long key();
+@Deprecated(since = "10.2")
+public interface KeyedObject {
+ /** Returns the key for this KeyedObject. */
+ public long key();
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObjectFactory.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObjectFactory.java
index 1bbc657b9f..2afd227914 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObjectFactory.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/KeyedObjectFactory.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +15,6 @@
*/
package ghidra.util.graph;
-
/** The KeyedObjectFactory class is responsible for ensuring that no two
vertices or edges have the same keys. One and only one instance of the
KeyedObjectFactory may exist. In addition to ensuring that all vertices
@@ -27,30 +25,26 @@ package ghidra.util.graph;
to a specific object since in theory there can be a one-to-many
correspondence.
*/
-public class KeyedObjectFactory
-{
- private long keyCounter = 0;
-
+@Deprecated(since = "10.2")
+public class KeyedObjectFactory {
+ private long keyCounter = 0;
- private KeyedObjectFactory()
- {
- //now is just a counter
- }
+ private KeyedObjectFactory() {
+ //now is just a counter
+ }
/** The singleton instance of KeyedObjectFactory. */
- static public KeyedObjectFactory instance_ = new KeyedObjectFactory();
-
- /** Returns singleton instance of KeyedObjectFactory. */
- static public KeyedObjectFactory getInstance()
- {
- return instance_;
- }
-
- /** Gets returns the next available key. The keys are given out based on a
- * one up counter. */
- synchronized long getNextAvailableKey()
- {
- return keyCounter++;
- }
+ static public KeyedObjectFactory instance_ = new KeyedObjectFactory();
+
+ /** Returns singleton instance of KeyedObjectFactory. */
+ static public KeyedObjectFactory getInstance() {
+ return instance_;
+ }
+
+ /** Gets returns the next available key. The keys are given out based on a
+ * one up counter. */
+ synchronized long getNextAvailableKey() {
+ return keyCounter++;
+ }
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Path.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Path.java
index 64d9f040b3..218cb272ad 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Path.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Path.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +17,7 @@ package ghidra.util.graph;
import java.util.Vector;
+@Deprecated(since = "10.2")
public class Path extends Vector {
public boolean containsInSomeElement(Vector otherVector) {
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/SimpleWeightedDigraph.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/SimpleWeightedDigraph.java
index 64c04512ca..1eeca31d4b 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/SimpleWeightedDigraph.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/SimpleWeightedDigraph.java
@@ -30,7 +30,8 @@ package ghidra.util.graph;
*
*
*/
-public class SimpleWeightedDigraph extends WeightedDigraph{
+@Deprecated(forRemoval = true, since = "10.2") // This class is no longer used or tested. Use GraphAlgorithms
+public class SimpleWeightedDigraph extends WeightedDigraph {
private final boolean allowLoops;
/**
@@ -51,9 +52,9 @@ public class SimpleWeightedDigraph extends WeightedDigraph{
* DoubleAttribute vertexWeights =
* (DoubleAttribute)this.vertexAttributes().createAttribute("weight", AttributeManager.DOUBLE_TYPE);
*/
- public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight, boolean loopsAllowed)
- {
- super( vertexCapacity, edgeCapacity, defaultEdgeWeight );
+ public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight,
+ boolean loopsAllowed) {
+ super(vertexCapacity, edgeCapacity, defaultEdgeWeight);
allowLoops = loopsAllowed;
}
@@ -65,9 +66,8 @@ public class SimpleWeightedDigraph extends WeightedDigraph{
* @param edgeCapacity
* @param defaultEdgeWeight
*/
- public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight)
- {
- super( vertexCapacity, edgeCapacity, defaultEdgeWeight );
+ public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight) {
+ super(vertexCapacity, edgeCapacity, defaultEdgeWeight);
allowLoops = false;
}
@@ -79,9 +79,8 @@ public class SimpleWeightedDigraph extends WeightedDigraph{
* @param vertexCapacity
* @param edgeCapacity
*/
- public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity)
- {
- super( vertexCapacity, edgeCapacity, 1.0 );
+ public SimpleWeightedDigraph(int vertexCapacity, int edgeCapacity) {
+ super(vertexCapacity, edgeCapacity, 1.0);
allowLoops = false;
}
@@ -95,16 +94,17 @@ public class SimpleWeightedDigraph extends WeightedDigraph{
* @return true if the edge was added sucessfully.
*/
@Override
- public boolean add( Edge e )
- {
- if( !allowLoops && (e.from() == e.to()) ) return false;
- Edge[] ft = this.getEdges( e.from() , e.to() );
- if( ft.length == 0 )
- {
- return super.add( e );
+ public boolean add(Edge e) {
+ if (!allowLoops && (e.from() == e.to())) {
+ return false;
+ }
+ Edge[] ft = this.getEdges(e.from(), e.to());
+ if (ft.length == 0) {
+ return super.add(e);
}
- return this.setWeight( ft[0] , this.getWeight( ft[0] ) + this.getDefaultEdgeWeight() );
+ return this.setWeight(ft[0], this.getWeight(ft[0]) + this.getDefaultEdgeWeight());
}
+
/**
* Add an edge with the the specified edge weight.
*
@@ -116,44 +116,40 @@ public class SimpleWeightedDigraph extends WeightedDigraph{
* @return true if the edge was added sucessfully.
*/
@Override
- public boolean add( Edge e, double weight )
- {
- if( !allowLoops && (e.from() == e.to()) ) return false;
- Edge[] ft = this.getEdges( e.from() , e.to() );
- if( ft.length == 0 )
- {
- return super.add( e , weight);
+ public boolean add(Edge e, double weight) {
+ if (!allowLoops && (e.from() == e.to())) {
+ return false;
}
- return this.setWeight( ft[0] , this.getWeight( ft[0] ) + weight );
+ Edge[] ft = this.getEdges(e.from(), e.to());
+ if (ft.length == 0) {
+ return super.add(e, weight);
+ }
+ return this.setWeight(ft[0], this.getWeight(ft[0]) + weight);
}
-
+
@Override
- public boolean remove( Edge e )
- {
- Edge[] ft = this.getEdges( e.from() , e.to() );
- if( ft.length == 0 ) {
+ public boolean remove(Edge e) {
+ Edge[] ft = this.getEdges(e.from(), e.to());
+ if (ft.length == 0) {
return false;
}
- return super.remove( ft[0] );
+ return super.remove(ft[0]);
}
-
-
+
@Override
- public double getWeight( Edge e )
- {
- Edge[] ft = this.getEdges( e.from() , e.to() );
- if( ft.length == 0 ) {
+ public double getWeight(Edge e) {
+ Edge[] ft = this.getEdges(e.from(), e.to());
+ if (ft.length == 0) {
return 0.0;
}
- return super.getWeight( ft[0] );
+ return super.getWeight(ft[0]);
}
-
-
+
@Override
- public DirectedGraph copy()
- {
- SimpleWeightedDigraph copy = new SimpleWeightedDigraph(this.numVertices(), this.numEdges(), this.getDefaultEdgeWeight(), allowLoops);
- copyAll( copy );
+ public DirectedGraph copy() {
+ SimpleWeightedDigraph copy = new SimpleWeightedDigraph(this.numVertices(), this.numEdges(),
+ this.getDefaultEdgeWeight(), allowLoops);
+ copyAll(copy);
return copy;
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Vertex.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Vertex.java
index f5d4b74fa3..0f8011d19c 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Vertex.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/Vertex.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +19,7 @@ package ghidra.util.graph;
* An implementation of vertices for use in ghidra.util.graph.
*
*/
+@Deprecated(forRemoval = true, since = "10.2")
public class Vertex implements KeyedObject, Comparable<Vertex> {
private final long key;
private final Object referent;
@@ -41,6 +41,7 @@ public class Vertex implements KeyedObject, Comparable<Vertex> {
/**
* @return The key of this vertex.
*/
+ @Override
public long key() {
return this.key;
}
@@ -85,6 +86,7 @@ public class Vertex implements KeyedObject, Comparable<Vertex> {
* Compares two vertices by keys. If the specified object o is not a Vertex a
* ClassCastException will be thrown.
*/
+ @Override
public int compareTo(Vertex v) {
long difference = (v.key() - this.key);
if (difference < 0) {
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/VertexSet.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/VertexSet.java
index c1f554e200..65dc9ab61d 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/VertexSet.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/VertexSet.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,425 +15,384 @@
*/
package ghidra.util.graph;
+import java.util.*;
+
import ghidra.util.Msg;
import ghidra.util.datastruct.LongIntHashtable;
import ghidra.util.exception.NoValueException;
-import java.util.*;
-
/**
* VertexSet is a container class for objects of type Vertex. It is
* designed to be used in conjunction with EdgeSet as part of DirectedGraph.
*
*
*/
-class VertexSet implements KeyIndexableSet<Vertex>
-{
- private final DirectedGraph parentGraph;
- private long modificationNumber;
- private int capacity;
- private int nextIndex = 0;
- private LongIntHashtable keyIndices;
- private Edge [] firstOutgoingEdge;
- private Edge [] firstIncomingEdge;
- private Edge [] lastOutgoingEdge;
- private Edge [] lastIncomingEdge;
- private Vertex [] vertices;
-
- /**
- * Constructor
- *
- * @param parent The DirectedGraph this is a VertexSet of.
- * @param capacity number of vertices that may be held without invoking grow()
- */
- public VertexSet( DirectedGraph parent, int capacity )
- {
- if( capacity < 10 ) capacity = 10;
- this.parentGraph = parent;
- this.modificationNumber = 0;
- this.capacity = capacity;
- keyIndices = new LongIntHashtable( capacity );
- firstOutgoingEdge = new Edge[capacity];
- firstIncomingEdge = new Edge[capacity];
- lastOutgoingEdge = new Edge[capacity];
- lastIncomingEdge = new Edge[capacity];
- vertices = new Vertex[capacity];
- }
-
-
- /**
- * Return the internal index of the given vertex within this edge set.
- * @return the internal index of o.
- * @throws ClassCastException if the object is not a Vertex.
- * @throws NoValueException if the KeyedObject is not in the VertexSet.
- */
- int index( Vertex v )
- {
- try{
- return keyIndices.get( v.key() );
- }catch( NoValueException exc ){
- return -1;
- }
- }
-
-
- /**
- * Adds the given vertex to the vertex set, if it does not already contain
- * it.
- *
- * @return true if and only if the vertex was sucessfully added.
- */
- public boolean add( Vertex v )
- {
- long key = v.key();
- if( !keyIndices.contains( key ) )
- {
- if( nextIndex >= capacity )
- {
- grow();
- }
- keyIndices.put( key, nextIndex );
- vertices[nextIndex++] = v;
- modificationNumber++;
- return true;
- }
- return false;
- }
-
- /**
- * Removes the given vertex from this vertex set if it contains it.
- * @return true if and only if the vertex was sucessfully removed.
- */
- public boolean remove( Vertex v )
- {
+@Deprecated(since = "10.2")
+class VertexSet implements KeyIndexableSet<Vertex> {
+ private final DirectedGraph parentGraph;
+ private long modificationNumber;
+ private int capacity;
+ private int nextIndex = 0;
+ private LongIntHashtable keyIndices;
+ private Edge[] firstOutgoingEdge;
+ private Edge[] firstIncomingEdge;
+ private Edge[] lastOutgoingEdge;
+ private Edge[] lastIncomingEdge;
+ private Vertex[] vertices;
+
+ /**
+ * Constructor
+ *
+ * @param parent The DirectedGraph this is a VertexSet of.
+ * @param capacity number of vertices that may be held without invoking grow()
+ */
+ public VertexSet(DirectedGraph parent, int capacity) {
+ if (capacity < 10) {
+ capacity = 10;
+ }
+ this.parentGraph = parent;
+ this.modificationNumber = 0;
+ this.capacity = capacity;
+ keyIndices = new LongIntHashtable(capacity);
+ firstOutgoingEdge = new Edge[capacity];
+ firstIncomingEdge = new Edge[capacity];
+ lastOutgoingEdge = new Edge[capacity];
+ lastIncomingEdge = new Edge[capacity];
+ vertices = new Vertex[capacity];
+ }
+
+ /**
+ * Return the internal index of the given vertex within this edge set.
+ * @return the internal index of o.
+ * @throws ClassCastException if the object is not a Vertex.
+ * @throws NoValueException if the KeyedObject is not in the VertexSet.
+ */
+ int index(Vertex v) {
+ try {
+ return keyIndices.get(v.key());
+ }
+ catch (NoValueException exc) {
+ return -1;
+ }
+ }
+
+ /**
+ * Adds the given vertex to the vertex set, if it does not already contain
+ * it.
+ *
+ * @return true if and only if the vertex was sucessfully added.
+ */
+ @Override
+ public boolean add(Vertex v) {
+ long key = v.key();
+ if (!keyIndices.contains(key)) {
+ if (nextIndex >= capacity) {
+ grow();
+ }
+ keyIndices.put(key, nextIndex);
+ vertices[nextIndex++] = v;
+ modificationNumber++;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Removes the given vertex from this vertex set if it contains it.
+ * @return true if and only if the vertex was sucessfully removed.
+ */
+ @Override
+ public boolean remove(Vertex v) {
if (v == null) {
return false;
}
- int index;
- long key = v.key();
- try
- {
- if( keyIndices.contains( key ) )
- {
- index = keyIndices.get( key );
- while( firstOutgoingEdge[index] != null )
- {
- parentGraph.remove( firstOutgoingEdge[index] );
- }
- while( firstIncomingEdge[index] != null )
- {
- parentGraph.remove( firstIncomingEdge[index] );
- }
- keyIndices.remove( key );
- vertices[index] = null;
- modificationNumber++;
- return true;
- }
- }
- catch( NoValueException e )
- {
- return false;
- }
- return false;
- }
+ int index;
+ long key = v.key();
+ try {
+ if (keyIndices.contains(key)) {
+ index = keyIndices.get(key);
+ while (firstOutgoingEdge[index] != null) {
+ parentGraph.remove(firstOutgoingEdge[index]);
+ }
+ while (firstIncomingEdge[index] != null) {
+ parentGraph.remove(firstIncomingEdge[index]);
+ }
+ keyIndices.remove(key);
+ vertices[index] = null;
+ modificationNumber++;
+ return true;
+ }
+ }
+ catch (NoValueException e) {
+ return false;
+ }
+ return false;
+ }
/**
* Return The number of vertices in this VertexSet.
*/
- public int size()
- {
- return keyIndices.size();
- }
+ @Override
+ public int size() {
+ return keyIndices.size();
+ }
/**
* Return true iff the specified KeyedObject is contained in
* this VertexSet.
*/
- public boolean contains( Vertex v )
- {
- if (v == null) {
- return false;
- }
- return keyIndices.contains( v.key() );
- }
+ @Override
+ public boolean contains(Vertex v) {
+ if (v == null) {
+ return false;
+ }
+ return keyIndices.contains(v.key());
+ }
/**
* Return the Vertex at the specified index. May be null.
*/
- private Vertex getByIndex( int index )
- {
- return vertices[index];
- }
-
- /**
- * Return the number of sources.
- * This equals the number of vertices with no incoming
- * edges in the VertexSet.
- */
- public int numSources()
- {
- int i, cnt = 0;
-
- for( i=0; i<nextIndex; i++ )
- {
- if( ( firstIncomingEdge[i] == null) && ( vertices[i] != null ) )
- {
- cnt++;
- }
- }
- return cnt;
- }
-
- /**
- * Return the number of sinks.
- * This equals the number of vertices with no outgoing
- * edges in the VertexSet.
- */
- public int numSinks()
- {
- int i, cnt = 0;
-
- for( i=0; i<nextIndex; i++ )
- {
- if( ( firstOutgoingEdge[i] == null) && (vertices[i] != null) )
- {
- cnt++;
- }
- }
- return cnt;
- }
+ private Vertex getByIndex(int index) {
+ return vertices[index];
+ }
+
+ /**
+ * Return the number of sources.
+ * This equals the number of vertices with no incoming
+ * edges in the VertexSet.
+ */
+ public int numSources() {
+ int i, cnt = 0;
+
+ for (i = 0; i < nextIndex; i++) {
+ if ((firstIncomingEdge[i] == null) && (vertices[i] != null)) {
+ cnt++;
+ }
+ }
+ return cnt;
+ }
+
+ /**
+ * Return the number of sinks.
+ * This equals the number of vertices with no outgoing
+ * edges in the VertexSet.
+ */
+ public int numSinks() {
+ int i, cnt = 0;
+
+ for (i = 0; i < nextIndex; i++) {
+ if ((firstOutgoingEdge[i] == null) && (vertices[i] != null)) {
+ cnt++;
+ }
+ }
+ return cnt;
+ }
/**
* Return a Vertex[] containing all vertices in the VertexSet that
* have no incoming edges. If there are none an array of length 0
* will be returned.
*/
- Vertex [] getSources()
- {
- int i=0, n, j=0;
-
- n = numSources();
- Vertex [] answer = new Vertex[n];
-
- while( (j < n) && (i < nextIndex) )
- {
- if( (firstIncomingEdge[i] == null) && (vertices[i] != null) )
- {
- answer[j++] = vertices[i];
- }
- i++;
- }
- return answer;
- }
+ Vertex[] getSources() {
+ int i = 0, n, j = 0;
+
+ n = numSources();
+ Vertex[] answer = new Vertex[n];
+
+ while ((j < n) && (i < nextIndex)) {
+ if ((firstIncomingEdge[i] == null) && (vertices[i] != null)) {
+ answer[j++] = vertices[i];
+ }
+ i++;
+ }
+ return answer;
+ }
/**
* Return a Vertex[] containing all vertices in the VertexSet that
* have no outgoing edges. If there are none an array of length 0
* will be returned.
*/
- Vertex [] getSinks()
- {
- int i=0, n, j=0;
-
- n = numSinks();
- Vertex [] answer = new Vertex[n];
-
- while( (j < n) && (i < nextIndex) )
- {
- if( (firstOutgoingEdge[i] == null) && (vertices[i] != null) )
- {
- answer[j++] = vertices[i];
- }
- i++;
- }
- return answer;
- }
+ Vertex[] getSinks() {
+ int i = 0, n, j = 0;
+
+ n = numSinks();
+ Vertex[] answer = new Vertex[n];
+
+ while ((j < n) && (i < nextIndex)) {
+ if ((firstOutgoingEdge[i] == null) && (vertices[i] != null)) {
+ answer[j++] = vertices[i];
+ }
+ i++;
+ }
+ return answer;
+ }
/**
* Get the first outgoing edge in the internal structures for this
* VertexSet for the parent DirectedGraph.
*/
- Edge getFirstOutgoingEdge( Vertex v )
- {
- //return firstOutgoingEdge[ index( v ) ];
- try{
- return firstOutgoingEdge[ keyIndices.get( v.key() ) ];
- }catch( NoValueException exc ){
- return null;
- }
- }
+ Edge getFirstOutgoingEdge(Vertex v) {
+ //return firstOutgoingEdge[ index( v ) ];
+ try {
+ return firstOutgoingEdge[keyIndices.get(v.key())];
+ }
+ catch (NoValueException exc) {
+ return null;
+ }
+ }
/**
* Get the last outgoing edge in the internal structures for this
* VertexSet for the parent DirectedGraph.
*/
- Edge getLastOutgoingEdge( Vertex v )
- {
- //return lastOutgoingEdge[ index( v ) ];
- try{
-
- Edge re = firstOutgoingEdge[ keyIndices.get( v.key() ) ];
- Edge e = re;
- EdgeSet es = parentGraph.edges();
- while( e != null )
- {
- re = e;
- e = es.getNextEdgeWithSameFrom( re );
- }
- return re;
- }catch( NoValueException exc ){
- return null;
- }
- }
-
+ Edge getLastOutgoingEdge(Vertex v) {
+ //return lastOutgoingEdge[ index( v ) ];
+ try {
+
+ Edge re = firstOutgoingEdge[keyIndices.get(v.key())];
+ Edge e = re;
+ EdgeSet es = parentGraph.edges();
+ while (e != null) {
+ re = e;
+ e = es.getNextEdgeWithSameFrom(re);
+ }
+ return re;
+ }
+ catch (NoValueException exc) {
+ return null;
+ }
+ }
/**
* Get the first incoming edge in the internal structures for this
* VertexSet for the parent DirectedGraph.
*/
- Edge getFirstIncomingEdge( Vertex v )
- {
- //return firstIncomingEdge[ index( v ) ];
- try{
- return firstIncomingEdge[ keyIndices.get( v.key() ) ];
- }catch( NoValueException exc ){
- return null;
- }
- }
+ Edge getFirstIncomingEdge(Vertex v) {
+ //return firstIncomingEdge[ index( v ) ];
+ try {
+ return firstIncomingEdge[keyIndices.get(v.key())];
+ }
+ catch (NoValueException exc) {
+ return null;
+ }
+ }
/**
* Get the last incoming edge in the internal structures for this
* VertexSet for the parent DirectedGraph.
*/
- Edge getLastIncomingEdge( Vertex v )
- {
- //return lastIncomingEdge[ index( v ) ];
- try{
- Edge re = firstIncomingEdge[ keyIndices.get( v.key() ) ];
- Edge e = re;
- EdgeSet es = parentGraph.edges();
- while( e != null )
- {
- re = e;
- e = es.getNextEdgeWithSameTo( re );
- }
- return re;
- }catch( NoValueException exc ){
- return null;
- }
- }
+ Edge getLastIncomingEdge(Vertex v) {
+ //return lastIncomingEdge[ index( v ) ];
+ try {
+ Edge re = firstIncomingEdge[keyIndices.get(v.key())];
+ Edge e = re;
+ EdgeSet es = parentGraph.edges();
+ while (e != null) {
+ re = e;
+ e = es.getNextEdgeWithSameTo(re);
+ }
+ return re;
+ }
+ catch (NoValueException exc) {
+ return null;
+ }
+ }
/**
* Set the first outgoing edge of v to be e.
* It is assumed that v has already been added to the graph.
*/
- void setFirstOutgoingEdge( Vertex v, Edge e )
- {
- try
- {
- firstOutgoingEdge[ index( v ) ] = e;
- }
- catch( ArrayIndexOutOfBoundsException exc )
- {
- Msg.error(this, "No Value Exception in setFirstOutgoingEdge()"
- + "\tVertex: " + v.toString()
- + "\tEdge: " + e.toString(), exc);
- }
- }
+ void setFirstOutgoingEdge(Vertex v, Edge e) {
+ try {
+ firstOutgoingEdge[index(v)] = e;
+ }
+ catch (ArrayIndexOutOfBoundsException exc) {
+ Msg.error(this, "No Value Exception in setFirstOutgoingEdge()" + "\tVertex: " +
+ v.toString() + "\tEdge: " + e.toString(), exc);
+ }
+ }
/**
* Set the last outgoing edge of v to be e.
* It is assumed that v has already been added to the graph.
*/
- void setLastOutgoingEdge( Vertex v, Edge e )
- {
- try
- {
- lastOutgoingEdge[ index( v ) ] = e;
- }
- catch( ArrayIndexOutOfBoundsException exc )
- {
- Msg.error(this, "No Value Exception in setLastOutgoingEdge()"
- + "\tVertex: " + v.toString()
- + "\tEdge: " + e.toString(), exc);
- }
- }
+ void setLastOutgoingEdge(Vertex v, Edge e) {
+ try {
+ lastOutgoingEdge[index(v)] = e;
+ }
+ catch (ArrayIndexOutOfBoundsException exc) {
+ Msg.error(this, "No Value Exception in setLastOutgoingEdge()" + "\tVertex: " +
+ v.toString() + "\tEdge: " + e.toString(), exc);
+ }
+ }
/**
* Set the first incoming edge of v to be e.
* It is assumed that v has already been added to the graph.
*/
- void setFirstIncomingEdge( Vertex v, Edge e )
- {
- try
- {
- firstIncomingEdge[ index( v ) ] = e;
- }
- catch( ArrayIndexOutOfBoundsException exc )
- {
- Msg.error(this, "No Value Exception in setFirstIncomingEdge()"
- + "\tVertex: " + v.toString()
- + "\tEdge: " + e.toString(), exc);
- }
-
- }
+ void setFirstIncomingEdge(Vertex v, Edge e) {
+ try {
+ firstIncomingEdge[index(v)] = e;
+ }
+ catch (ArrayIndexOutOfBoundsException exc) {
+ Msg.error(this, "No Value Exception in setFirstIncomingEdge()" + "\tVertex: " +
+ v.toString() + "\tEdge: " + e.toString(), exc);
+ }
+
+ }
/**
* Set the last incoming edge of v to be e.
* It is assumed that v has already been added to the graph.
*/
- void setLastIncomingEdge( Vertex v, Edge e )
- {
- try
- {
- lastIncomingEdge[ index( v ) ] = e;
- }
- catch( ArrayIndexOutOfBoundsException exc )
- {
- Msg.error(this, "No Value Exception in setLastIncomingEdge()"
- + "\tVertex: " + v.toString()
- + "\tEdge: " + e.toString(), exc);
- }
- }
+ void setLastIncomingEdge(Vertex v, Edge e) {
+ try {
+ lastIncomingEdge[index(v)] = e;
+ }
+ catch (ArrayIndexOutOfBoundsException exc) {
+ Msg.error(this, "No Value Exception in setLastIncomingEdge()" + "\tVertex: " +
+ v.toString() + "\tEdge: " + e.toString(), exc);
+ }
+ }
/**
* Remove all of the vertices from this VertexSet without changing
* the capacity. Much faster than removing each vertex individually.
* The EdgeSet for this graph gets cleared first.
*/
- void clear()
- {
- modificationNumber++;
- EdgeSet es = parentGraph.edges();
- if( es.size() > 0 )
- {
- es.clear();
- }
- if( size() > 0 )
- {
- nextIndex = 0;
- keyIndices.removeAll();
- for( int i = 0; i<capacity; i++ )
- {
- firstOutgoingEdge[i] = null;
- firstIncomingEdge[i] = null;
- lastOutgoingEdge[i] = null;
- lastIncomingEdge[i] = null;
- vertices[i] = null;
- }
- }
- }
-
- /*
- * @see ghidra.util.graph.KeyIndexableSet#getKeyedObject(long)
- */
+ void clear() {
+ modificationNumber++;
+ EdgeSet es = parentGraph.edges();
+ if (es.size() > 0) {
+ es.clear();
+ }
+ if (size() > 0) {
+ nextIndex = 0;
+ keyIndices.removeAll();
+ for (int i = 0; i < capacity; i++) {
+ firstOutgoingEdge[i] = null;
+ firstIncomingEdge[i] = null;
+ lastOutgoingEdge[i] = null;
+ lastIncomingEdge[i] = null;
+ vertices[i] = null;
+ }
+ }
+ }
+
+ /*
+ * @see ghidra.util.graph.KeyIndexableSet#getKeyedObject(long)
+ */
+ @Override
public Vertex getKeyedObject(long key) {
- if (keyIndices.contains(key))
+ if (keyIndices.contains(key)) {
try {
return vertices[keyIndices.get(key)];
- } catch (Exception e) {
+ }
+ catch (Exception e) {
return null;
}
+ }
return null;
}
@@ -451,225 +409,203 @@ class VertexSet implements KeyIndexableSet<Vertex>
// Err.debug(this, "\n");
// }
- /**
- * Return the number of vertices this VertexSet may hold without growing.
- */
- public int capacity()
- {
- return this.capacity;
- }
+ /**
+ * Return the number of vertices this VertexSet may hold without growing.
+ */
+ @Override
+ public int capacity() {
+ return this.capacity;
+ }
/**
* Increases the capacity of the VertexSet so additional vertices
* can be added.
*/
- void grow()
- {
- modificationNumber++;
- if( (keyIndices.size()*13)>(capacity*9) )
- {
- int newCapacity = (int)Math.round(keyIndices.size() * 1.7) + 7;
-
- Edge [] newFirstOutgoingEdge = new Edge[newCapacity];
- Edge [] newFirstIncomingEdge = new Edge[newCapacity];
- Edge [] newLastOutgoingEdge = new Edge[newCapacity];
- Edge [] newLastIncomingEdge = new Edge[newCapacity];
- Vertex [] newVertices = new Vertex[newCapacity];
-
- nextIndex=0;
- for( int i=0; i<capacity; i++ )
- {
- if( vertices[i] != null )
- {
- newVertices[nextIndex] = vertices[i];
- newFirstOutgoingEdge[nextIndex] = firstOutgoingEdge[i];
- newFirstIncomingEdge[nextIndex] = firstIncomingEdge[i];
- newLastOutgoingEdge[nextIndex] = lastOutgoingEdge[i];
- newLastIncomingEdge[nextIndex] = lastIncomingEdge[i];
- keyIndices.remove( vertices[i].key() );
- keyIndices.put( vertices[i].key(), nextIndex);
- nextIndex++;
- }
- }
- capacity = newCapacity;
- vertices = newVertices;
- firstOutgoingEdge = newFirstOutgoingEdge;
- firstIncomingEdge = newFirstIncomingEdge;
- lastOutgoingEdge = newLastOutgoingEdge;
- lastIncomingEdge = newLastIncomingEdge;
- }
- else// tighten up
- {
- tighten();
- }
- }
-
- /**
- * Clean up the internal storage of the VertexSet.
- */
- private void tighten()
- {
- modificationNumber++;
- // tighten up
- nextIndex = 0;
- for( int i=0; i<capacity; i++ )
- {
- if( vertices[i] != null )
- {
- if( i > nextIndex )
- {
- vertices[nextIndex] = vertices[i];
- firstOutgoingEdge[nextIndex] = firstOutgoingEdge[i];
- firstIncomingEdge[nextIndex] = firstIncomingEdge[i];
- lastOutgoingEdge[nextIndex] = lastOutgoingEdge[i];
- lastIncomingEdge[nextIndex] = lastIncomingEdge[i];
- keyIndices.remove( vertices[i].key() );
- keyIndices.put( vertices[i].key(), nextIndex);
- vertices[i] = null;
- firstOutgoingEdge[i] = null;
- firstIncomingEdge[i] = null;
- lastOutgoingEdge[i] = null;
- lastIncomingEdge[i] = null;
- }
- nextIndex++;
- }
- }
- }
+ void grow() {
+ modificationNumber++;
+ if ((keyIndices.size() * 13) > (capacity * 9)) {
+ int newCapacity = (int) Math.round(keyIndices.size() * 1.7) + 7;
+
+ Edge[] newFirstOutgoingEdge = new Edge[newCapacity];
+ Edge[] newFirstIncomingEdge = new Edge[newCapacity];
+ Edge[] newLastOutgoingEdge = new Edge[newCapacity];
+ Edge[] newLastIncomingEdge = new Edge[newCapacity];
+ Vertex[] newVertices = new Vertex[newCapacity];
+
+ nextIndex = 0;
+ for (int i = 0; i < capacity; i++) {
+ if (vertices[i] != null) {
+ newVertices[nextIndex] = vertices[i];
+ newFirstOutgoingEdge[nextIndex] = firstOutgoingEdge[i];
+ newFirstIncomingEdge[nextIndex] = firstIncomingEdge[i];
+ newLastOutgoingEdge[nextIndex] = lastOutgoingEdge[i];
+ newLastIncomingEdge[nextIndex] = lastIncomingEdge[i];
+ keyIndices.remove(vertices[i].key());
+ keyIndices.put(vertices[i].key(), nextIndex);
+ nextIndex++;
+ }
+ }
+ capacity = newCapacity;
+ vertices = newVertices;
+ firstOutgoingEdge = newFirstOutgoingEdge;
+ firstIncomingEdge = newFirstIncomingEdge;
+ lastOutgoingEdge = newLastOutgoingEdge;
+ lastIncomingEdge = newLastIncomingEdge;
+ }
+ else// tighten up
+ {
+ tighten();
+ }
+ }
+
+ /**
+ * Clean up the internal storage of the VertexSet.
+ */
+ private void tighten() {
+ modificationNumber++;
+ // tighten up
+ nextIndex = 0;
+ for (int i = 0; i < capacity; i++) {
+ if (vertices[i] != null) {
+ if (i > nextIndex) {
+ vertices[nextIndex] = vertices[i];
+ firstOutgoingEdge[nextIndex] = firstOutgoingEdge[i];
+ firstIncomingEdge[nextIndex] = firstIncomingEdge[i];
+ lastOutgoingEdge[nextIndex] = lastOutgoingEdge[i];
+ lastIncomingEdge[nextIndex] = lastIncomingEdge[i];
+ keyIndices.remove(vertices[i].key());
+ keyIndices.put(vertices[i].key(), nextIndex);
+ vertices[i] = null;
+ firstOutgoingEdge[i] = null;
+ firstIncomingEdge[i] = null;
+ lastOutgoingEdge[i] = null;
+ lastIncomingEdge[i] = null;
+ }
+ nextIndex++;
+ }
+ }
+ }
/**
* Get the number of times this VertexSet has changed
*/
- public long getModificationNumber()
- {
- return this.modificationNumber;
- }
+ @Override
+ public long getModificationNumber() {
+ return this.modificationNumber;
+ }
/**
* Return an iterator over all of the vertices in this VertexSet.
* The iterator becomes invalid and throws a ConcurrentModificationException
* if any changes are made to the VertexSet after the iterator is created.
*/
- public GraphIterator<Vertex> iterator()
- {
- return new VertexSetIterator();
- }
-
+ @Override
+ public GraphIterator<Vertex> iterator() {
+ return new VertexSetIterator();
+ }
/**
* Return the elements of this VertexSet as a java.util.Set.
*/
- public Set<Vertex> toSet()
- {
- Set<Vertex> vs = new HashSet<Vertex>( this.size() );
- GraphIterator<Vertex> i = this.iterator();
- while( i.hasNext() )
- {
- vs.add(i.next() );
- }
- return vs;
- }
+ public Set<Vertex> toSet() {
+ Set<Vertex> vs = new HashSet<>(this.size());
+ GraphIterator<Vertex> i = this.iterator();
+ while (i.hasNext()) {
+ vs.add(i.next());
+ }
+ return vs;
+ }
/**
* Return the elements of this VertexSet as an Vertex[].
*/
- public Vertex[] toArray()
- {
- Vertex[] theVertices = new Vertex[this.size()];
- int i=0, cnt = 0;
- int done = this.size();
- while( cnt < done )
- {
- if( vertices[i] != null )
- {
- theVertices[cnt++] = vertices[i];
- }
- i++;
- }
- return theVertices;
- }
+ @Override
+ public Vertex[] toArray() {
+ Vertex[] theVertices = new Vertex[this.size()];
+ int i = 0, cnt = 0;
+ int done = this.size();
+ while (cnt < done) {
+ if (vertices[i] != null) {
+ theVertices[cnt++] = vertices[i];
+ }
+ i++;
+ }
+ return theVertices;
+ }
/**
* Implements an Iterator for this VertexSet.
*/
- private class VertexSetIterator implements GraphIterator<Vertex>
- {
- private int currentPosition;
- private int nextPosition;
- private long setModificationNumber;
-
+ private class VertexSetIterator implements GraphIterator<Vertex> {
+ private int currentPosition;
+ private int nextPosition;
+ private long setModificationNumber;
+
/**
* Constructor
*/
- public VertexSetIterator() // VertexSet cvs)
- {
- currentPosition = -1;
- nextPosition = -1;
- this.setModificationNumber = getModificationNumber();
- getNextPosition();
- }
-
- private void getNextPosition()
- {
- nextPosition++;
- while( (nextPosition < capacity() ) && ( getByIndex(nextPosition) == null ))
- {
- nextPosition++;
- }
- }
-
+ public VertexSetIterator() // VertexSet cvs)
+ {
+ currentPosition = -1;
+ nextPosition = -1;
+ this.setModificationNumber = getModificationNumber();
+ getNextPosition();
+ }
+
+ private void getNextPosition() {
+ nextPosition++;
+ while ((nextPosition < capacity()) && (getByIndex(nextPosition) == null)) {
+ nextPosition++;
+ }
+ }
+
/**
* Return true if there is another vertex in this iteration.
* @throws ConcurrentModificationException if the VertexSet is
* modified by methods outside this iterator.
*/
- public boolean hasNext() throws ConcurrentModificationException
- {
- if( setModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Set Modified");
- }
-
- if( nextPosition < capacity() )
- {
- return true;
- }
- return false;
- }
-
+ @Override
+ public boolean hasNext() throws ConcurrentModificationException {
+ if (setModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Set Modified");
+ }
+
+ if (nextPosition < capacity()) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Return the next Vertex in the iteration
*/
- public Vertex next() throws ConcurrentModificationException
- {
- if( setModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Set Modified");
- }
- if( nextPosition < capacity() )
- {
- currentPosition = nextPosition;
- getNextPosition();
- return getByIndex(currentPosition);
- }
- throw new NoSuchElementException();
- }
-
+ @Override
+ public Vertex next() throws ConcurrentModificationException {
+ if (setModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Set Modified");
+ }
+ if (nextPosition < capacity()) {
+ currentPosition = nextPosition;
+ getNextPosition();
+ return getByIndex(currentPosition);
+ }
+ throw new NoSuchElementException();
+ }
+
/**
* Remove the vertex returned by the most recent call to next().
*/
- public boolean remove() throws ConcurrentModificationException
- {
- boolean removed;
- if( setModificationNumber != getModificationNumber() )
- {
- throw new ConcurrentModificationException("Set Modified");
- }
- removed = VertexSet.this.remove( getByIndex(currentPosition) );
- setModificationNumber = getModificationNumber();
- return removed;
- }
-
+ @Override
+ public boolean remove() throws ConcurrentModificationException {
+ boolean removed;
+ if (setModificationNumber != getModificationNumber()) {
+ throw new ConcurrentModificationException("Set Modified");
+ }
+ removed = VertexSet.this.remove(getByIndex(currentPosition));
+ setModificationNumber = getModificationNumber();
+ return removed;
+ }
+
}
}
-
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/WeightedDigraph.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/WeightedDigraph.java
index 23d745aeac..13859e5a68 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/WeightedDigraph.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/WeightedDigraph.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,198 +24,174 @@ import ghidra.util.graph.attributes.DoubleAttribute;
*
*
*/
+@Deprecated(forRemoval = true, since = "10.2") // This class is no longer used or tested. Use GraphAlgorithms
public class WeightedDigraph extends DirectedGraph {
- //private DoubleAttribute weights;
- private double defaultValue = 1.0;
+ //private DoubleAttribute weights;
+ private double defaultValue = 1.0;
/** Create weighted directed graph with default edge weight of 0.0
* and room for vertexCapicity vertices and edgeCapacity edges.
*/
- public WeightedDigraph( int vertexCapacity, int edgeCapacity )
- {
- super( vertexCapacity, edgeCapacity );
- this.edgeAttributes().createAttribute( "weight", AttributeManager.DOUBLE_TYPE);
- }
-
- private DoubleAttribute<Edge> weights()
- {
- return (DoubleAttribute<Edge>) this.edgeAttributes().getAttribute("weight");
- }
+ public WeightedDigraph(int vertexCapacity, int edgeCapacity) {
+ super(vertexCapacity, edgeCapacity);
+ this.edgeAttributes().createAttribute("weight", AttributeManager.DOUBLE_TYPE);
+ }
+
+ private DoubleAttribute<Edge> weights() {
+ return (DoubleAttribute<Edge>) this.edgeAttributes().getAttribute("weight");
+ }
- /** Create a weighted directed graph. Use the defaultEdgeWeight for any edges whose
- * weights have not been set.
- */
- public WeightedDigraph( int vertexCapacity, int edgeCapacity, double defaultEdgeWeight )
- {
- super( vertexCapacity, edgeCapacity );
- defaultValue = defaultEdgeWeight;
- this.edgeAttributes().createAttribute( "weight", AttributeManager.DOUBLE_TYPE);
- }
+ /** Create a weighted directed graph. Use the defaultEdgeWeight for any edges whose
+ * weights have not been set.
+ */
+ public WeightedDigraph(int vertexCapacity, int edgeCapacity, double defaultEdgeWeight) {
+ super(vertexCapacity, edgeCapacity);
+ defaultValue = defaultEdgeWeight;
+ this.edgeAttributes().createAttribute("weight", AttributeManager.DOUBLE_TYPE);
+ }
- /** Default constructor */
- public WeightedDigraph()
- {
- this( 101, 101 );
- }
+ /** Default constructor */
+ public WeightedDigraph() {
+ this(101, 101);
+ }
/** Returns the weighted in-degree of this vertex. The in-degree is the
* sum of weights of all enges entering this vertex.
*/
@Override
- public double inDegree( Vertex v )
- {
- double degree = 0.0;
- Edge[] edges = this.incomingEdges( v );
- int length = edges.length;
- for( int i=0; i< length; i++ )
- {
- try
- {
- degree += weights().getValue( edges[i] );
- }
- catch( NoValueException exc )
- {
- degree += defaultValue;
- }
- }
- return degree;
+ public double inDegree(Vertex v) {
+ double degree = 0.0;
+ Edge[] edges = this.incomingEdges(v);
+ int length = edges.length;
+ for (int i = 0; i < length; i++) {
+ try {
+ degree += weights().getValue(edges[i]);
+ }
+ catch (NoValueException exc) {
+ degree += defaultValue;
+ }
+ }
+ return degree;
}
-
+
/** Returns the weighted out-degree of this vertex. The out-degree is the
* sum of weights of all enges entering this vertex.
*/
@Override
- public double outDegree( Vertex v )
- {
- double degree = 0.0;
- Edge[] edges = this.outgoingEdges( v );
- int length = edges.length;
- for( int i=0; i< length; i++ )
- {
- try
- {
- degree += weights().getValue( edges[i] );
- }
- catch( NoValueException exc )
- {
- degree += defaultValue;
- }
- }
- return degree;
+ public double outDegree(Vertex v) {
+ double degree = 0.0;
+ Edge[] edges = this.outgoingEdges(v);
+ int length = edges.length;
+ for (int i = 0; i < length; i++) {
+ try {
+ degree += weights().getValue(edges[i]);
+ }
+ catch (NoValueException exc) {
+ degree += defaultValue;
+ }
+ }
+ return degree;
}
-
+
/** Returns the weighted self-degree of this vertex. The self-degree is the
* sum of weights of all loops at this vertex.
*/
- public double selfDegree( Vertex v )
- {
- double degree = 0.0;
- Edge[] edges = this.selfEdges( v );
- int length = edges.length;
- for( int i=0; i< length; i++ )
- {
- try
- {
- degree += weights().getValue( edges[i] );
- }
- catch( NoValueException exc )
- {
- degree += 0.0;
- }
- }
- return degree;
+ public double selfDegree(Vertex v) {
+ double degree = 0.0;
+ Edge[] edges = this.selfEdges(v);
+ int length = edges.length;
+ for (int i = 0; i < length; i++) {
+ try {
+ degree += weights().getValue(edges[i]);
+ }
+ catch (NoValueException exc) {
+ degree += 0.0;
+ }
+ }
+ return degree;
}
-
+
/** Returns the weighted degree of this vertex. The degree is the
* sum of weights of all edges entering and leaving this vertex.
*/
@Override
- public double degree( Vertex v )
- {
- return inDegree( v ) + outDegree( v ) - selfDegree( v );
+ public double degree(Vertex v) {
+ return inDegree(v) + outDegree(v) - selfDegree(v);
}
/** Returns the weight of the specified edge.
*/
- public double getWeight( Edge e )
- {
- try
- {
- return weights().getValue( e );
+ public double getWeight(Edge e) {
+ try {
+ return weights().getValue(e);
}
- catch( NoValueException ex )
- {
+ catch (NoValueException ex) {
return 0.0;
}
}
-
+
/** Sets the weight of the specified edge.
*/
- public boolean setWeight( Edge e, double value )
- {
- return weights().setValue( e, value );
- }
-
+ public boolean setWeight(Edge e, double value) {
+ return weights().setValue(e, value);
+ }
+
/** Gets the defaultEdgeWeight of this graph specified at creation
* time.
*/
- public double getDefaultEdgeWeight()
- {
+ public double getDefaultEdgeWeight() {
return defaultValue;
}
-
+
/** Add an edge. If successful (i.e. that edge does not already appear
* in the graph), set the weight to the default value
* @return true if edge added succesfuly.
*/
@Override
- public boolean add( Edge e )
- {
- double wt = getWeight( e );
- boolean returnValue = super.add( e );
- if( returnValue )
- setWeight( e, defaultValue );
- else
- setWeight( e, wt + defaultValue );
+ public boolean add(Edge e) {
+ double wt = getWeight(e);
+ boolean returnValue = super.add(e);
+ if (returnValue) {
+ setWeight(e, defaultValue);
+ }
+ else {
+ setWeight(e, wt + defaultValue);
+ }
return true;
}
-
+
/** Add an edge. If successful (i.e. that edge does not appear in the graph),
* then set the weight to the specified value.
*
* @return true if edge added succesfuly.
*/
- public boolean add( Edge e, double weight )
- {
- double wt = getWeight( e );
- super.add( e );
- setWeight( e, wt + weight );
+ public boolean add(Edge e, double weight) {
+ double wt = getWeight(e);
+ super.add(e);
+ setWeight(e, wt + weight);
return true;
}
-
+
/** Get the edge weights for this graph. */
- public DoubleAttribute<Edge> getEdgeWeights()
- {
+ public DoubleAttribute<Edge> getEdgeWeights() {
return this.weights();
}
-
-
+
@Override
- public DirectedGraph copy()
- {
- WeightedDigraph copy = new WeightedDigraph(this.numVertices(), this.numEdges(), this.getDefaultEdgeWeight());
- copyAll( copy );
+ public DirectedGraph copy() {
+ WeightedDigraph copy =
+ new WeightedDigraph(this.numVertices(), this.numEdges(), this.getDefaultEdgeWeight());
+ copyAll(copy);
return copy;
}
-
-
+
/** Creates intersection of graphs in place by adding all vertices and edges of
* other graph to this graph. This method used to return a different graph
* as the intersection but now does not.
*
*/
@Override
- public void intersectionWith(DirectedGraph otherGraph) {
+ public void intersectionWith(DirectedGraph otherGraph) {
GraphIterator<Vertex> vi = otherGraph.vertexIterator();
Vertex v;
while (vi.hasNext()) {
@@ -240,8 +215,9 @@ public class WeightedDigraph extends DirectedGraph {
* as the union but now does not.
*/
@Override
- public void unionWith(DirectedGraph otherGraph) {
- DoubleAttribute<Edge> otherWts = (DoubleAttribute<Edge>) otherGraph.edgeAttributes().getAttribute("weight");
+ public void unionWith(DirectedGraph otherGraph) {
+ DoubleAttribute<Edge> otherWts =
+ (DoubleAttribute<Edge>) otherGraph.edgeAttributes().getAttribute("weight");
GraphIterator<Vertex> vi = otherGraph.vertexIterator();
while (vi.hasNext()) {
add(vi.next());
@@ -250,13 +226,12 @@ public class WeightedDigraph extends DirectedGraph {
while (ei.hasNext()) {
Edge e = ei.next();
try {
- add( e , otherWts.getValue( e ));
- } catch (NoValueException e1) {
- add( e );
+ add(e, otherWts.getValue(e));
+ }
+ catch (NoValueException e1) {
+ add(e);
}
}
}
-
-
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/LongAttribute.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/LongAttribute.java
index ff1a969e6f..1bacc6185b 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/LongAttribute.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/LongAttribute.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +15,13 @@
*/
package ghidra.util.graph.attributes;
+import java.util.Arrays;
+import java.util.Comparator;
+
import ghidra.util.exception.NoValueException;
import ghidra.util.graph.KeyIndexableSet;
import ghidra.util.graph.KeyedObject;
-import java.util.Arrays;
-import java.util.Comparator;
-
/** This class provides a storage mechanism for long-valued information about
* the elements of a KeyIndexableSet, e.g. the vertices of a DirectedGraph.
*/
@@ -127,8 +126,9 @@ public class LongAttribute<T extends KeyedObject> extends Attribute<T> {
else if ((ko1.key() - ko2.key()) > 0) {
return +1;
}
- else
+ else {
return 0;
+ }
}
}
catch (NoValueException exc2) {
@@ -148,8 +148,9 @@ public class LongAttribute<T extends KeyedObject> extends Attribute<T> {
else if ((ko1.key() - ko2.key()) > 0) {
return +1;
}
- else
+ else {
return 0;
+ }
}
}
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/package.html b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/package.html
index 2226bf9805..fa06e27526 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/package.html
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/attributes/package.html
@@ -1,5 +1,7 @@
<html>
<body>
-Provides classes and interfaces for defining attributes on vertices or edges of graphs.
+
+This package is deprecated with no replacement.
+
</body>
</html>
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/package.html b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/package.html
index 7b0b2efc6f..2cb992058d 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/package.html
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/package.html
@@ -6,8 +6,8 @@
<body>
-<p>Contains graph package useful for creating, manipulating,
-and answering questions about directed graphs. </p>
+<p>Most of the code in this package is deprecated. See the class javadoc for
+details. </p>
</body>