Interface SparseGraphSpecifics

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default boolean assertEdgeExist​(java.lang.Integer e)
      Ensures that the specified edge exists in this graph, or else throws exception.
      default boolean assertVertexExist​(java.lang.Integer v)
      Ensures that the specified vertex exists in this graph, or else throws exception.
      default boolean containsEdge​(java.lang.Integer e)
      Returns true if this graph contains the specified edge.
      default boolean containsVertex​(java.lang.Integer v)
      Returns true if this graph contains the specified vertex.
      long degreeOf​(java.lang.Integer vertex)
      Returns the degree of the specified vertex.
      long edgesCount()
      Get the number of edges.
      default java.util.Set<java.lang.Integer> edgeSet()
      Returns a set of the edges contained in this graph.
      java.util.Set<java.lang.Integer> edgesOf​(java.lang.Integer vertex)
      Returns a set of all edges touching the specified vertex.
      java.util.Set<java.lang.Integer> getAllEdges​(java.lang.Integer sourceVertex, java.lang.Integer targetVertex)
      Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph.
      java.lang.Integer getEdge​(java.lang.Integer sourceVertex, java.lang.Integer targetVertex)
      Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.
      java.lang.Integer getEdgeSource​(java.lang.Integer e)
      Returns the source vertex of an edge.
      java.lang.Integer getEdgeTarget​(java.lang.Integer e)
      Returns the target vertex of an edge.
      default double getEdgeWeight​(java.lang.Integer e)
      Returns the weight assigned to a given edge.
      GraphType getType()
      Get the graph type.
      java.util.Set<java.lang.Integer> incomingEdgesOf​(java.lang.Integer vertex)
      Returns a set of all edges incoming into the specified vertex.
      long inDegreeOf​(java.lang.Integer vertex)
      Returns the "in degree" of the specified vertex.
      long outDegreeOf​(java.lang.Integer vertex)
      Returns the "out degree" of the specified vertex.
      java.util.Set<java.lang.Integer> outgoingEdgesOf​(java.lang.Integer vertex)
      Returns a set of all edges outgoing from the specified vertex.
      default void setEdgeWeight​(java.lang.Integer e, double weight)
      Assigns a weight to an edge.
      default java.util.Set<java.lang.Integer> vertexSet()
      Returns a set of the vertices contained in this graph.
      long verticesCount()
      Get the number of vertices
    • Method Detail

      • 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​(java.lang.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​(java.lang.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 java.util.Set<java.lang.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​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
        java.lang.ArithmeticException - if the result overflows an int
      • edgesOf

        java.util.Set<java.lang.Integer> edgesOf​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
      • inDegreeOf

        long inDegreeOf​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
        java.lang.ArithmeticException - if the result overflows an int
      • incomingEdgesOf

        java.util.Set<java.lang.Integer> incomingEdgesOf​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
      • outDegreeOf

        long outDegreeOf​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
        java.lang.ArithmeticException - if the result overflows an int
      • outgoingEdgesOf

        java.util.Set<java.lang.Integer> outgoingEdgesOf​(java.lang.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:
        java.lang.IllegalArgumentException - if vertex is not found in the graph.
        java.lang.NullPointerException - if vertex is null.
      • vertexSet

        default java.util.Set<java.lang.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

        java.lang.Integer getEdgeSource​(java.lang.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

        java.lang.Integer getEdgeTarget​(java.lang.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​(java.lang.Integer e)
        Returns the weight assigned to a given edge. Unweighted graphs return 1.0 (as defined by #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​(java.lang.Integer e,
                                   double weight)
        Assigns a weight to an edge.
        Parameters:
        e - edge on which to set weight
        weight - new weight for edge
        Throws:
        java.lang.UnsupportedOperationException - if the graph does not support weights
      • getEdge

        java.lang.Integer getEdge​(java.lang.Integer sourceVertex,
                                  java.lang.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

        java.util.Set<java.lang.Integer> getAllEdges​(java.lang.Integer sourceVertex,
                                                     java.lang.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​(java.lang.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:
        java.lang.IllegalArgumentException - if specified vertex does not exist in this graph.
      • assertEdgeExist

        default boolean assertEdgeExist​(java.lang.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:
        java.lang.IllegalArgumentException - if specified edge does not exist in this graph.