Class SimpleGraph<T extends IDable,M>

java.lang.Object
dev.roanh.gmark.util.SimpleGraph<T,M>
Type Parameters:
T - The vertex data type
M - The metadata data type

public class SimpleGraph<T extends IDable,M> extends Object
Implementation of a simple graph that only supports unlabelled undirected edges. Parallel edges are not supported, but self loops are allowed. Vertices in the graph are uniquely identified by some piece of data.
  • Field Details

  • Constructor Details

    • SimpleGraph

      public SimpleGraph(int vertexCount)
      Constructs a new simple graph with capacity for the given number of vertices. Note that all vertices added should have an ID that is lower than the vertex count.
      Parameters:
      vertexCount - The number of vertices to allocate space for.
  • Method Details

    • deleteVertex

      public void deleteVertex(SimpleGraph.SimpleVertex<T,M> vertex)
      Deletes the given vertex from the graph.
      Parameters:
      vertex - The vertex to delete
    • getVertex

      public SimpleGraph.SimpleVertex<T,M> getVertex(T data)
      Gets a vertex from this graph using the data that uniquely identifies it.
      Parameters:
      data - The data uniquely identifying the requested vertex.
      Returns:
      The vertex associated with the passed data.
    • getEdges

      public Set<SimpleGraph.SimpleEdge<T,M>> getEdges()
      Gets all the edges in this graph.
      Returns:
      All the edges in this graph.
    • addVertex

      public SimpleGraph.SimpleVertex<T,M> addVertex(T data)
      Adds a new vertex to this graph with the given piece of uniquely identifying data.
      Parameters:
      data - The data that uniquely identifies this vertex,
      Returns:
      The newly added vertex or the already existing vertex if a vertex identified by the same piece of data was already present in the graph.
    • addEdge

      public SimpleGraph.SimpleEdge<T,M> addEdge(T a, T b)
      Adds a new edge to this graph between the vertices identified by the given pieces of data.
      Parameters:
      a - The data uniquely identifying the first vertex.
      b - The data uniquely identifying the second vertex.
      Returns:
      The newly added edge.
    • addEdge

      Adds a new edge to this graph between the given vertex and the vertex associated with the given data.
      Parameters:
      a - The first vertex
      b - The data uniquely identifying the second vertex.
      Returns:
      The newly added edge.
    • addEdge

      Adds a new edge to this graph between the given two vertices.
      Parameters:
      a - The first vertex.
      b - The second vertex.
      Returns:
      The newly added edge.
    • getVertexCount

      public int getVertexCount()
      Gets the total number of vertices in this graph.
      Returns:
      The total number of vertices in this graph.
    • getEdgeCount

      public int getEdgeCount()
      Gets the total number of edges in this graph.
      Returns:
      The total number of edges in this graph.
    • getVertices

      public List<SimpleGraph.SimpleVertex<T,M>> getVertices()
      Gets all the vertices in this graph.
      Returns:
      All the vertices in this graph.
    • toUniqueGraph

      public UniqueGraph<T,Void> toUniqueGraph()
      Converts this simple graph to a unique graph instance. For this conversion edges will remain unlabelled and a directed edge will be added in both directions between vertices that are connected in this graph.
      Returns:
      The newly constructed unique graph instance.
    • dropAllEdges

      public void dropAllEdges()
      Deletes all edges in this graph.