- java.lang.Object
-
- it.unive.lisa.util.datastructures.graph.BaseGraph<G,N,E>
-
- Type Parameters:
G
- the type of this graphN
- the type ofNode
s in this graphE
- the type ofEdge
s in this graph
- All Implemented Interfaces:
Graph<G,N,E>
- Direct Known Subclasses:
CallGraph
public abstract class BaseGraph<G extends BaseGraph<G,N,E>,N extends Node<G,N,E>,E extends Edge<G,N,E>> extends java.lang.Object implements Graph<G,N,E>
A genericGraph
, backed by anAdjacencyMatrix
.
Note that this class does not defineObject.equals(Object)
norObject.hashCode()
, since we leave the decision to be unique instances to implementers.
-
-
Field Summary
Fields Modifier and Type Field Description protected AdjacencyMatrix<G,N,E>
adjacencyMatrix
The adjacency matrix of this graph, mapping nodes to the collection of edges attached to it.protected java.util.Collection<N>
entrypoints
The nodes of this graph that are entrypoints, that is, that can be executed from other graphs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(E edge)
Adds an edge to this graph.void
addNode(N node)
Adds the given node to the set of nodes.void
addNode(N node, boolean entrypoint)
Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).boolean
containsEdge(E edge)
Yieldstrue
if the given edge is contained in this graph.boolean
containsNode(N node)
Yieldstrue
if 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.AdjacencyMatrix<G,N,E>
getAdjacencyMatrix()
Yields the adjacency matrix backing this graph.E
getEdgeConnecting(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.int
getEdgesCount()
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.int
getNodesCount()
Yields the total number of nodes of this graph.java.util.Collection<E>
getOutgoingEdges(N node)
Yields the outgoing edges from the given node.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.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.SerializableGraph
toSerializableGraph(java.util.function.BiFunction<G,N,SerializableValue> descriptionGenerator)
Yields an instance ofSerializableGraph
built from this one.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.util.datastructures.graph.Graph
accept, getCycleEntries, toSerializableGraph
-
-
-
-
Constructor Detail
-
BaseGraph
protected BaseGraph()
Builds the graph.
-
BaseGraph
protected BaseGraph(java.util.Collection<N> entrypoints, AdjacencyMatrix<G,N,E> adjacencyMatrix)
Builds the graph.- Parameters:
entrypoints
- the nodes of this graph that will be reachable from other graphsadjacencyMatrix
- the matrix containing all the nodes and the edges that will be part of this graph
-
BaseGraph
protected BaseGraph(G other)
Clones the given graph.- Parameters:
other
- the original graph
-
-
Method Detail
-
getAdjacencyMatrix
public AdjacencyMatrix<G,N,E> getAdjacencyMatrix()
Yields the adjacency matrix backing this graph.- Returns:
- the matrix
-
getEntrypoints
public java.util.Collection<N> getEntrypoints()
Description copied from interface:Graph
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.
-
getNodes
public java.util.Collection<N> getNodes()
Description copied from interface:Graph
Yields the set of nodes of this graph.
-
getEdges
public java.util.Collection<E> getEdges()
Description copied from interface:Graph
Yields the set of edges of this graph.
-
addNode
public void addNode(N node)
Description copied from interface:Graph
Adds the given node to the set of nodes. This is equivalent to invokingGraph.addNode(Node, boolean)
withfalse
as second parameter.
-
addNode
public void addNode(N node, boolean entrypoint)
Description copied from interface:Graph
Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).
-
addEdge
public void addEdge(E edge)
Description copied from interface:Graph
Adds an edge to this graph.
-
getNodesCount
public int getNodesCount()
Description copied from interface:Graph
Yields the total number of nodes of this graph.
-
getEdgesCount
public int getEdgesCount()
Description copied from interface:Graph
Yields the total number of edges of this graph.
-
containsNode
public boolean containsNode(N node)
Description copied from interface:Graph
Yieldstrue
if the given node is contained in this graph.
-
containsEdge
public boolean containsEdge(E edge)
Description copied from interface:Graph
Yieldstrue
if the given edge is contained in this graph.
-
getEdgeConnecting
public E getEdgeConnecting(N source, N destination)
Description copied from interface:Graph
Yields the edge connecting the two given nodes, if any. Yieldsnull
if 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, useGraph.getEdgesConnecting(Node, Node)
.
-
getEdgesConnecting
public java.util.Collection<E> getEdgesConnecting(N source, N destination)
Description copied from interface:Graph
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.
-
getIngoingEdges
public java.util.Collection<E> getIngoingEdges(N node)
Description copied from interface:Graph
Yields the ingoing edges to the given node.
-
getOutgoingEdges
public java.util.Collection<E> getOutgoingEdges(N node)
Description copied from interface:Graph
Yields the outgoing edges from the given node.
-
followersOf
public java.util.Collection<N> followersOf(N node)
Description copied from interface:Graph
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. Yieldsnull
if the node is not in this graph.
-
predecessorsOf
public java.util.Collection<N> predecessorsOf(N node)
Description copied from interface:Graph
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. Yieldsnull
if the node is not in this graph.
-
toSerializableGraph
public SerializableGraph toSerializableGraph(java.util.function.BiFunction<G,N,SerializableValue> descriptionGenerator)
Description copied from interface:Graph
Yields an instance ofSerializableGraph
built from this one. IfdescriptionGenerator
is notnull
,SerializableNodeDescription
for each node will be generated using it.
-
isEqualTo
public boolean isEqualTo(G graph)
Description copied from interface: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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-