Package ghidra.service.graph
Class AttributedGraph
java.lang.Object
org.jgrapht.graph.AbstractGraph<AttributedVertex,AttributedEdge>
org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,AttributedEdge>
ghidra.service.graph.AttributedGraph
- All Implemented Interfaces:
Serializable
,Cloneable
,org.jgrapht.Graph<AttributedVertex,
AttributedEdge>
public class AttributedGraph
extends org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,AttributedEdge>
Basic graph implementation for a directed graph whose vertices and edges support attributes.
The graph can be configured as to how to handle multiple edges with the same source and destination vertices. One option is to simply allow multiple edges. The second option is to collapse duplicate edges such that there is only ever one edge with the same source and destination. In this case, each additional duplicate edge added will cause the edge to have a "Weight" attribute that will be the total number of edges that were added to the same source/destination vertex pair.
- See Also:
-
Field Summary
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT
-
Constructor Summary
ConstructorDescriptionAttributedGraph
(String name, GraphType type) Create a new empty AttributedGraph that automatically collapses duplicate edgesAttributedGraph
(String name, GraphType type, String description) Create a new empty AttributedGraph that automatically collapses duplicate edgesAttributedGraph
(String name, GraphType type, String description, boolean collapseDuplicateEdges) Create a new empty AttributedGraph. -
Method Summary
Modifier and TypeMethodDescriptionaddEdge
(AttributedVertex source, AttributedVertex target) Creates and adds a new directed edge between the given source and target vertices.boolean
addEdge
(AttributedVertex source, AttributedVertex target, AttributedEdge edge) Creates and adds a new directed edge with the given edge object.addEdge
(AttributedVertex source, AttributedVertex target, String edgeId) Creates and adds a new directed edge with the given id between the given source and target vertices.boolean
addVertex
(AttributedVertex vertex) Adds a new vertex with the given id.Adds a new vertex with the given id and name.Returns a description of the graphint
Returns the total number of edges in the graphReturns theGraphType
for this graphgetName()
Returns the name of the graphReturns the vertex with the given vertex idint
Returns the total number of vertices in the graphMethods inherited from class org.jgrapht.graph.AbstractBaseGraph
clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, iterables, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSupplier, setEdgeWeight, setVertexSupplier, vertexSet
Methods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jgrapht.Graph
containsEdge, removeAllEdges, removeAllEdges, removeAllVertices, setEdgeWeight
-
Field Details
-
WEIGHT
- See Also:
-
-
Constructor Details
-
AttributedGraph
Create a new empty AttributedGraph that automatically collapses duplicate edges- Parameters:
name
- the name of the graphtype
- theGraphType
which defines valid vertex and edge types.
-
AttributedGraph
Create a new empty AttributedGraph that automatically collapses duplicate edges- Parameters:
name
- the name of the graphtype
- theGraphType
which defines valid vertex and edge types.description
- a description of the graph
-
AttributedGraph
public AttributedGraph(String name, GraphType type, String description, boolean collapseDuplicateEdges) Create a new empty AttributedGraph.- Parameters:
name
- the name of the graphtype
- theGraphType
which defines valid vertex and edge types.description
- a description of the graphcollapseDuplicateEdges
- if true, duplicate edges will be collapsed into a single edge with a "Weight" attribute whose value is the number of edges between those vertices.
-
-
Method Details
-
getName
Returns the name of the graph- Returns:
- the name of the graph
-
getDescription
Returns a description of the graph- Returns:
- a description of the graph
-
getGraphType
Returns theGraphType
for this graph- Returns:
- the
GraphType
for this graph
-
addVertex
Adds a new vertex with the given id. The vertex's name will be the same as the id. If a vertex already exists with that id, then that vertex will be returned.- Parameters:
id
- the unique vertex id that the graph should have a vertex for.- Returns:
- either an existing vertex with that id, or a newly added vertex with that id
-
addVertex
Adds a new vertex with the given id and name. If a vertex already exists with that id, then that vertex will be returned, but with its name changed to the given name.- Parameters:
id
- the unique vertex id that the graph should have a vertex for.vertexName
- the name to associate with this vertex- Returns:
- either an existing vertex with that id, or a newly added vertex with that id
-
addVertex
- Specified by:
addVertex
in interfaceorg.jgrapht.Graph<AttributedVertex,
AttributedEdge> - Overrides:
addVertex
in classorg.jgrapht.graph.AbstractBaseGraph<AttributedVertex,
AttributedEdge>
-
addVertex
- Specified by:
addVertex
in interfaceorg.jgrapht.Graph<AttributedVertex,
AttributedEdge> - Overrides:
addVertex
in classorg.jgrapht.graph.AbstractBaseGraph<AttributedVertex,
AttributedEdge>
-
addEdge
Creates and adds a new directed edge with the given id between the given source and target vertices. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.- Parameters:
source
- the source vertex of the directed edge to be created.target
- the target vertex of the directed edge to be created.edgeId
- the id to use for the new edge. Note: if this is a duplicate and edges are being collapsed, then this edgeId will not be used.- Returns:
- a new edge between the source and target if it is the first one or the graph is not collapsing edges. Otherwise, an existing edge with its "Weight" attribute set accordingly.
-
addEdge
Creates and adds a new directed edge with the given edge object. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.- Specified by:
addEdge
in interfaceorg.jgrapht.Graph<AttributedVertex,
AttributedEdge> - Overrides:
addEdge
in classorg.jgrapht.graph.AbstractBaseGraph<AttributedVertex,
AttributedEdge> - Parameters:
source
- the source vertex of the directed edge to be created.target
- the target vertex of the directed edge to be created.edge
- the BasicEdge object to use for the new edge. Note: if this is a duplicate and edges are being collapsed, then this edge object will not be used.- Returns:
- true if the edge was added. Note that if this graph is collapsing duplicate edges, then it will always return true.
-
addEdge
Creates and adds a new directed edge between the given source and target vertices. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.- Specified by:
addEdge
in interfaceorg.jgrapht.Graph<AttributedVertex,
AttributedEdge> - Overrides:
addEdge
in classorg.jgrapht.graph.AbstractBaseGraph<AttributedVertex,
AttributedEdge> - Parameters:
source
- the source vertex of the directed edge to be created.target
- the target vertex of the directed edge to be created.- Returns:
- a new edge between the source and target if it is the first one or the graph is not collapsing edges. Otherwise, an existing edge with its "Weight" attribute set accordingly.
-
getEdgeCount
public int getEdgeCount()Returns the total number of edges in the graph- Returns:
- the total number of edges in the graph
-
getVertexCount
public int getVertexCount()Returns the total number of vertices in the graph- Returns:
- the total number of vertices in the graph
-
getVertex
Returns the vertex with the given vertex id- Parameters:
vertexId
- the id of the vertex to retrieve- Returns:
- the vertex with the given vertex id or null if none found
-