-
- Type Parameters:
G- the type of this graphN- the type ofNodes in this graphE- the type ofEdges in this graph
- All Known Implementing Classes:
BaseCallGraph,BaseGraph,CFG,CFGWithAnalysisResults,CodeGraph
public interface Graph<G extends Graph<G,N,E>,N extends Node<G,N,E>,E extends Edge<G,N,E>>Interface of a generic graph structure.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> voidaccept(GraphVisitor<G,N,E,V> visitor, V tool)Accepts the givenGraphVisitor.voidaddEdge(E edge)Adds an edge to this graph.voidaddNode(N node)Adds the given node to the set of nodes.voidaddNode(N node, boolean entrypoint)Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).booleancontainsEdge(E edge)Yieldstrueif the given edge is contained in this graph.booleancontainsNode(N node)Yieldstrueif the given node is contained in this graph.java.util.Collection<N>followersOf(N node)Yields the collection of the nodes that are followers of the given one, that is, all nodes such that there exist an edge in this control flow graph going from the given node to such node.EgetEdgeConnecting(N source, N destination)Yields the edge connecting the two given nodes, if any.java.util.Collection<E>getEdges()Yields the set of edges of this graph.java.util.Collection<E>getEdgesConnecting(N source, N destination)Yields all edges connecting the two given nodes, if any.intgetEdgesCount()Yields the total number of edges of this graph.java.util.Collection<N>getEntrypoints()Yields the nodes of this graph that are entrypoints, that is, roots of the graph.java.util.Collection<E>getIngoingEdges(N node)Yields the ingoing edges to the given node.java.util.Collection<N>getNodes()Yields the set of nodes of this graph.intgetNodesCount()Yields the total number of nodes of this graph.java.util.Collection<E>getOutgoingEdges(N node)Yields the outgoing edges from the given node.booleanisEqualTo(G graph)Checks if this graph is effectively equal to the given one, that is, if they have the same structure while potentially being different instances.java.util.Collection<N>predecessorsOf(N node)Yields the collection of the nodes that are predecessors of the given vertex, that is, all nodes such that there exist an edge in this control flow graph going from such node to the given one.default SerializableGraphtoSerializableGraph()Yields an instance ofSerializableGraphbuilt from this one.SerializableGraphtoSerializableGraph(java.util.function.Function<N,SerializableValue> descriptionGenerator)Yields an instance ofSerializableGraphbuilt from this one.
-
-
-
Method Detail
-
getEntrypoints
java.util.Collection<N> getEntrypoints()
Yields the nodes of this graph that are entrypoints, that is, roots of the graph. This usually contains the first node of this graph, but might also contain other ones.- Returns:
- the entrypoints of this graph
-
getNodes
java.util.Collection<N> getNodes()
Yields the set of nodes of this graph.- Returns:
- the collection of nodes
-
getEdges
java.util.Collection<E> getEdges()
Yields the set of edges of this graph.- Returns:
- the collection of edges
-
addNode
void addNode(N node)
Adds the given node to the set of nodes. This is equivalent to invokingaddNode(Node, boolean)withfalseas second parameter.- Parameters:
node- the node to add
-
addNode
void addNode(N node, boolean entrypoint)
Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).- Parameters:
node- the node to addentrypoint- iftruecauses the given node to be considered as an entrypoint.
-
addEdge
void addEdge(E edge)
Adds an edge to this graph.- Parameters:
edge- the edge to add- Throws:
java.lang.UnsupportedOperationException- if the source or the destination of the given edge are not part of this graph
-
getNodesCount
int getNodesCount()
Yields the total number of nodes of this graph.- Returns:
- the number of nodes
-
getEdgesCount
int getEdgesCount()
Yields the total number of edges of this graph.- Returns:
- the number of edges
-
containsNode
boolean containsNode(N node)
Yieldstrueif the given node is contained in this graph.- Parameters:
node- the node to check- Returns:
trueif the node is in this graph
-
containsEdge
boolean containsEdge(E edge)
Yieldstrueif the given edge is contained in this graph.- Parameters:
edge- the edge to check- Returns:
trueif the edge is in this graph
-
getEdgeConnecting
E getEdgeConnecting(N source, N destination)
Yields the edge connecting the two given nodes, if any. Yieldsnullif such edge does not exist, or if one of the two nodes is not inside this graph. If more than one edge connects the two nodes, this method returns one of them arbitrarily (but consistently: successive calls with the same parameters will always return the same edge). To retrieve all such edges, usegetEdgesConnecting(Node, Node).- Parameters:
source- the source nodedestination- the destination node- Returns:
- the edge connecting
sourcetodestination, ornull
-
getEdgesConnecting
java.util.Collection<E> getEdgesConnecting(N source, N destination)
Yields all edges connecting the two given nodes, if any. Yields an empty collection if no edge exists, or if one of the two nodes is not inside this graph.- Parameters:
source- the source nodedestination- the destination node- Returns:
- the edges connecting
sourcetodestination
-
getIngoingEdges
java.util.Collection<E> getIngoingEdges(N node)
Yields the ingoing edges to the given node.- Parameters:
node- the node- Returns:
- the collection of ingoing edges
-
getOutgoingEdges
java.util.Collection<E> getOutgoingEdges(N node)
Yields the outgoing edges from the given node.- Parameters:
node- the node- Returns:
- the collection of outgoing edges
-
followersOf
java.util.Collection<N> followersOf(N node)
Yields the collection of the nodes that are followers of the given one, that is, all nodes such that there exist an edge in this control flow graph going from the given node to such node. Yieldsnullif the node is not in this graph.- Parameters:
node- the node- Returns:
- the collection of followers
-
predecessorsOf
java.util.Collection<N> predecessorsOf(N node)
Yields the collection of the nodes that are predecessors of the given vertex, that is, all nodes such that there exist an edge in this control flow graph going from such node to the given one. Yieldsnullif the node is not in this graph.- Parameters:
node- the node- Returns:
- the collection of predecessors
-
toSerializableGraph
default SerializableGraph toSerializableGraph()
Yields an instance ofSerializableGraphbuilt from this one. The default implementation of this method is equivalent to invokingtoSerializableGraph(Function)withnullas argument.- Returns:
- a
SerializableGraphinstance
-
toSerializableGraph
SerializableGraph toSerializableGraph(java.util.function.Function<N,SerializableValue> descriptionGenerator)
Yields an instance ofSerializableGraphbuilt from this one. IfdescriptionGeneratoris notnull,SerializableNodeDescriptionfor each node will be generated using it.- Parameters:
descriptionGenerator- the function to be used for generating node descriptions, can benull- Returns:
- a
SerializableGraphinstance
-
isEqualTo
boolean isEqualTo(G graph)
Checks if this graph is effectively equal to the given one, that is, if they have the same structure while potentially being different instances.- Parameters:
graph- the other graph- Returns:
trueif this graph and the given one are effectively equals
-
accept
default <V> void accept(GraphVisitor<G,N,E,V> visitor, V tool)
Accepts the givenGraphVisitor. This method first invokesGraphVisitor.visit(Object, Graph)on this graph, and then proceeds by first invokingGraphVisitor.visit(Object, Graph, Node)on all the nodes in the order they are returned bygetNodes(), and later invokingGraphVisitor.visit(Object, Graph, Edge)on all the edges in the order they are returned bygetEdges(). The visiting stops at the first of such calls that returnfalse.- Type Parameters:
V- the type of auxiliary tool thatvisitorcan use- Parameters:
visitor- the visitor that is visiting theGraphcontaining this graphtool- the auxiliary tool thatvisitorcan use
-
-