Package ghidra.graph

Class MutableGDirectedGraphWrapper<V,​E extends GEdge<V>>

  • Type Parameters:
    V - the vertex type
    E - the edge type
    All Implemented Interfaces:
    GDirectedGraph<V,​E>

    public class MutableGDirectedGraphWrapper<V,​E extends GEdge<V>>
    extends java.lang.Object
    implements GDirectedGraph<V,​E>
    A class that can wrap a GDirectedGraph and allows for vertex and edge additions without changing the underlying graph.

    Warning: As mentioned above, this graph is meant for additive operations. In its current form, removal operations will not work. To facilitate removals, this class will have to be updated to track removed vertices and edges, using them to correctly report the state of the graph for methods like containsVertex(Object) and containsEdge(GEdge).

    Implementation Note: there is some 'magic' in this class to add 'dummy' vertices to the graph. To facilitate this, the mutated graph in this class does not have the V type, but rather is typed on Object. This means that this class can only be used generically, with templated types (like by algorithms and such). Any usage of this class that expects concrete implementations to be returned can trigger ClassCastExceptions.

    • Constructor Detail

      • MutableGDirectedGraphWrapper

        public MutableGDirectedGraphWrapper​(GDirectedGraph<V,​E> delegate)
    • Method Detail

      • addDummyVertex

        public V addDummyVertex​(java.lang.String name)
      • isDummy

        public boolean isDummy​(V v)
      • isDummy

        public boolean isDummy​(E e)
      • addDummyEdge

        public E addDummyEdge​(V start,
                              V end)
      • addVertex

        public boolean addVertex​(V v)
        Description copied from interface: GDirectedGraph
        Add a vertex
        Specified by:
        addVertex in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the vertex
        Returns:
        true if the add was successful, false otherwise
      • removeVertices

        public void removeVertices​(java.lang.Iterable<V> vertices)
        Description copied from interface: GDirectedGraph
        Removes the given vertices from the graph
        Specified by:
        removeVertices in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        vertices - the vertices to remove
      • removeEdges

        public void removeEdges​(java.lang.Iterable<E> edges)
        Description copied from interface: GDirectedGraph
        Removes the given edges from the graph
        Specified by:
        removeEdges in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        edges - the edges to remove
      • removeEdge

        public boolean removeEdge​(E e)
        Description copied from interface: GDirectedGraph
        Removes an edge
        Specified by:
        removeEdge in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        e - the edge
        Returns:
        true if the graph contained the given edge
      • getVertices

        public java.util.Collection<V> getVertices()
        Description copied from interface: GDirectedGraph
        Retrieve all the vertices
        Specified by:
        getVertices in interface GDirectedGraph<V,​E extends GEdge<V>>
        Returns:
        the vertices
      • getEdges

        public java.util.Collection<E> getEdges()
        Description copied from interface: GDirectedGraph
        Retrieve all the edges
        Specified by:
        getEdges in interface GDirectedGraph<V,​E extends GEdge<V>>
        Returns:
        the edges
      • containsVertex

        public boolean containsVertex​(V v)
        Description copied from interface: GDirectedGraph
        Test if the graph contains a given vertex
        Specified by:
        containsVertex in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the vertex
        Returns:
        true if the vertex is in the graph, or false
      • containsEdge

        public boolean containsEdge​(E e)
        Description copied from interface: GDirectedGraph
        Test if the graph contains a given edge
        Specified by:
        containsEdge in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        e - the ege
        Returns:
        true if the edge is in the graph, or false
      • containsEdge

        public boolean containsEdge​(V from,
                                    V to)
        Description copied from interface: GDirectedGraph
        Test if the graph contains an edge from one given vertex to another
        Specified by:
        containsEdge in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        from - the source vertex
        to - the destination vertex
        Returns:
        true if such an edge exists, or false
      • findEdge

        public E findEdge​(V start,
                          V end)
        Description copied from interface: GDirectedGraph
        Locates the edge object for the two vertices
        Specified by:
        findEdge in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        start - the start vertex
        end - the end vertex
        Returns:
        the edge
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: GDirectedGraph
        Test if the graph is empty, i.e., contains no vertices or edges
        Specified by:
        isEmpty in interface GDirectedGraph<V,​E extends GEdge<V>>
        Returns:
        true if the graph is empty, or false
      • getInEdges

        public java.util.Collection<E> getInEdges​(V v)
        Description copied from interface: GDirectedGraph
        Compute the incident edges that end at the given vertex
        Specified by:
        getInEdges in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the destination vertex
        Returns:
        the in-edges to the given vertex
      • getOutEdges

        public java.util.Collection<E> getOutEdges​(V v)
        Description copied from interface: GDirectedGraph
        Compute the incident edges that start at the given vertex
        Specified by:
        getOutEdges in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the source vertex
        Returns:
        the out-edges from the given vertex
      • getPredecessors

        public java.util.Collection<V> getPredecessors​(V v)
        Description copied from interface: GDirectedGraph
        Compute a vertex's predecessors

        The default implementation computes this from the in-edges

        Specified by:
        getPredecessors in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the destination vertex
        Returns:
        the predecessors
      • getSuccessors

        public java.util.Collection<V> getSuccessors​(V v)
        Description copied from interface: GDirectedGraph
        Compute a vertex's successors

        The default implementation compute this from the out-edges

        Specified by:
        getSuccessors in interface GDirectedGraph<V,​E extends GEdge<V>>
        Parameters:
        v - the source vertex
        Returns:
        the successors
      • copy

        public GDirectedGraph<V,​E> copy()
        Description copied from interface: GDirectedGraph
        Copy this graph.

        Note: the vertices and edges in the copy may be the same instances in the new graph and not themselves copies.

        Specified by:
        copy in interface GDirectedGraph<V,​E extends GEdge<V>>
        Returns:
        the new copy
      • emptyCopy

        public GDirectedGraph<V,​E> emptyCopy()
        Description copied from interface: GDirectedGraph
        Creates a new instance of this graph with no vertices or edges. This is useful when you wish to build a new graph using the same type as this graph.
        Specified by:
        emptyCopy in interface GDirectedGraph<V,​E extends GEdge<V>>
        Returns:
        the new copy