Interface SparseGraphSpecifics

All Known Implementing Classes:
IncidenceMatrixSparseUndirectedSpecifics, IncomingNoReindexSparseDirectedSpecifics, NoIncomingNoReindexSparseDirectedSpecifics

public interface SparseGraphSpecifics
Specifics which provide a sparse graph implementation.
  • Method Details

    • edgesCount

      long edgesCount()
      Get the number of edges.
      Returns:
      the number of edges
    • verticesCount

      long verticesCount()
      Get the number of vertices
      Returns:
      the number of vertices
    • containsEdge

      default boolean containsEdge(Integer e)
      Returns true if this graph contains the specified edge. More formally, returns true if and only if this graph contains an edge e2 such that e.equals(e2). If the specified edge is null returns false.
      Parameters:
      e - edge whose presence in this graph is to be tested.
      Returns:
      true if this graph contains the specified edge.
    • containsVertex

      default boolean containsVertex(Integer v)
      Returns true if this graph contains the specified vertex. More formally, returns true if and only if this graph contains a vertex u such that u.equals(v). If the specified vertex is null returns false.
      Parameters:
      v - vertex whose presence in this graph is to be tested.
      Returns:
      true if this graph contains the specified vertex.
    • edgeSet

      default Set<Integer> edgeSet()
      Returns a set of the edges contained in this graph. The set is backed by the graph, so changes to the graph are reflected in the set. If the graph is modified while an iteration over the set is in progress, the results of the iteration are undefined.

      The graph implementation may maintain a particular set ordering (e.g. via LinkedHashSet) for deterministic iteration, but this is not required. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.

      Returns:
      a set of the edges contained in this graph.
    • degreeOf

      long degreeOf(Integer vertex)
      Returns the degree of the specified vertex.

      A degree of a vertex in an undirected graph is the number of edges touching that vertex. Edges with same source and target vertices (self-loops) are counted twice.

      In directed graphs this method returns the sum of the "in degree" and the "out degree".

      Parameters:
      vertex - vertex whose degree is to be calculated.
      Returns:
      the degree of the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
      ArithmeticException - if the result overflows an int
    • edgesOf

      Set<Integer> edgesOf(Integer vertex)
      Returns a set of all edges touching the specified vertex. If no edges are touching the specified vertex returns an empty set.
      Parameters:
      vertex - the vertex for which a set of touching edges is to be returned.
      Returns:
      a set of all edges touching the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
    • inDegreeOf

      long inDegreeOf(Integer vertex)
      Returns the "in degree" of the specified vertex.

      The "in degree" of a vertex in a directed graph is the number of inward directed edges from that vertex. See http://mathworld.wolfram.com/Indegree.html.

      In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.

      Parameters:
      vertex - vertex whose degree is to be calculated.
      Returns:
      the degree of the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
      ArithmeticException - if the result overflows an int
    • incomingEdgesOf

      Set<Integer> incomingEdgesOf(Integer vertex)
      Returns a set of all edges incoming into the specified vertex.

      In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.

      Parameters:
      vertex - the vertex for which the list of incoming edges to be returned.
      Returns:
      a set of all edges incoming into the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
    • outDegreeOf

      long outDegreeOf(Integer vertex)
      Returns the "out degree" of the specified vertex.

      The "out degree" of a vertex in a directed graph is the number of outward directed edges from that vertex. See http://mathworld.wolfram.com/Outdegree.html.

      In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.

      Parameters:
      vertex - vertex whose degree is to be calculated.
      Returns:
      the degree of the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
      ArithmeticException - if the result overflows an int
    • outgoingEdgesOf

      Set<Integer> outgoingEdgesOf(Integer vertex)
      Returns a set of all edges outgoing from the specified vertex.

      In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.

      Parameters:
      vertex - the vertex for which the list of outgoing edges to be returned.
      Returns:
      a set of all edges outgoing from the specified vertex.
      Throws:
      IllegalArgumentException - if vertex is not found in the graph.
      NullPointerException - if vertex is null.
    • vertexSet

      default Set<Integer> vertexSet()
      Returns a set of the vertices contained in this graph. The set is backed by the graph, so changes to the graph are reflected in the set. If the graph is modified while an iteration over the set is in progress, the results of the iteration are undefined.

      The graph implementation may maintain a particular set ordering (e.g. via LinkedHashSet) for deterministic iteration, but this is not required. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.

      Returns:
      a set view of the vertices contained in this graph.
    • getEdgeSource

      Integer getEdgeSource(Integer e)
      Returns the source vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).
      Parameters:
      e - edge of interest
      Returns:
      source vertex
    • getEdgeTarget

      Integer getEdgeTarget(Integer e)
      Returns the target vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).
      Parameters:
      e - edge of interest
      Returns:
      target vertex
    • getType

      GraphType getType()
      Get the graph type. The graph type can be used to query for additional metadata such as whether the graph supports directed or undirected edges, self-loops, multiple (parallel) edges, weights, etc.
      Returns:
      the graph type
    • getEdgeWeight

      default double getEdgeWeight(Integer e)
      Returns the weight assigned to a given edge. Unweighted graphs return 1.0 (as defined by
      invalid reference
      #DEFAULT_EDGE_WEIGHT
      ), allowing weighted-graph algorithms to apply to them when meaningful.
      Parameters:
      e - edge of interest
      Returns:
      edge weight
    • setEdgeWeight

      default void setEdgeWeight(Integer e, double weight)
      Assigns a weight to an edge.
      Parameters:
      e - edge on which to set weight
      weight - new weight for edge
      Throws:
      UnsupportedOperationException - if the graph does not support weights
    • getEdge

      Integer getEdge(Integer sourceVertex, Integer targetVertex)
      Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph. Otherwise returns null. If any of the specified vertices is null returns null

      In undirected graphs, the returned edge may have its source and target vertices in the opposite order.

      Parameters:
      sourceVertex - source vertex of the edge.
      targetVertex - target vertex of the edge.
      Returns:
      an edge connecting source vertex to target vertex.
    • getAllEdges

      Set<Integer> getAllEdges(Integer sourceVertex, Integer targetVertex)
      Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph. If any of the vertices does not exist or is null, returns null. If both vertices exist but no edges found, returns an empty set.

      In undirected graphs, some of the returned edges may have their source and target vertices in the opposite order. In simple graphs the returned set is either singleton set or empty set.

      Parameters:
      sourceVertex - source vertex of the edge.
      targetVertex - target vertex of the edge.
      Returns:
      a set of all edges connecting source vertex to target vertex.
    • assertVertexExist

      default boolean assertVertexExist(Integer v)
      Ensures that the specified vertex exists in this graph, or else throws exception.
      Parameters:
      v - vertex
      Returns:
      true if this assertion holds.
      Throws:
      IllegalArgumentException - if specified vertex does not exist in this graph.
    • assertEdgeExist

      default boolean assertEdgeExist(Integer e)
      Ensures that the specified edge exists in this graph, or else throws exception.
      Parameters:
      e - edge
      Returns:
      true if this assertion holds.
      Throws:
      IllegalArgumentException - if specified edge does not exist in this graph.