Class GraphBaseWithEdgeEndpointsContainer

    • Method Detail

      • addEdge

        public int addEdge​(int source,
                           int target)
        Description copied from interface: IndexGraph
        Add a new edge to the graph.

        The graph implementation will choose a new int identifier which is not currently used as one of the graph edges, and will return it as the new edge ID.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Specified by:
        addEdge in interface IndexGraph
        Specified by:
        addEdge in interface IntGraph
        Parameters:
        source - a source vertex
        target - a target vertex
        Returns:
        the new edge identifier
      • clearEdges

        public void clearEdges()
        Description copied from interface: IndexGraph
        Remove all the edges from the graph.

        Note that this function also clears any weights associated with the edges.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Specified by:
        clearEdges in interface Graph<Integer,​Integer>
        Specified by:
        clearEdges in interface IndexGraph
      • edgeEndpoints

        public long[] edgeEndpoints()
      • setEndpoints

        public default void setEndpoints​(int edge,
                                         int source,
                                         int target)
      • edgeEndpoint

        public default int edgeEndpoint​(int edge,
                                        int endpoint)
        Description copied from interface: IntGraph
        Get the other end-point of an edge.

        Given an edge \((u,v)\) and a vertex \(w\), assuming \(w\) is an endpoint of the edge, namely that \(w\) is either \(u\) or \(v\), the method will return the other endpoint which is not \(w\). If \(w=u\) the method will return \(v\), if \(w=v\) the method will return \(u\).

        Specified by:
        edgeEndpoint in interface IntGraph
        Parameters:
        edge - an edge identifier
        endpoint - one of the edge end-point
        Returns:
        the other end-point of the edge
      • edgeSource

        public default int edgeSource​(int edge)
        Description copied from interface: IntGraph
        Get the source vertex of an edge.

        If the graph is undirected, this function return an arbitrary end-point of the edge, but always other end-point than IntGraph.edgeTarget(int) returns.

        Specified by:
        edgeSource in interface IntGraph
        Parameters:
        edge - the edge identifier
        Returns:
        the edge source vertex
      • edgeTarget

        public default int edgeTarget​(int edge)
        Description copied from interface: IntGraph
        Get the target vertex of an edge.

        If the graph is undirected, this function return an arbitrary end-point of the edge, but always the other end-point than IntGraph.edgeSource(int) returns.

        Specified by:
        edgeTarget in interface IntGraph
        Parameters:
        edge - the edge identifier
        Returns:
        the edge target vertex
      • replaceEdgeSource

        public default void replaceEdgeSource​(int edge,
                                              int newSource)
      • replaceEdgeTarget

        public default void replaceEdgeTarget​(int edge,
                                              int newTarget)
      • replaceEdgeEndpoint

        public default void replaceEdgeEndpoint​(int edge,
                                                int oldEndpoint,
                                                int newEndpoint)
      • vertices

        public final com.jgalgo.graph.GraphElementSet vertices()
        Description copied from interface: IndexGraph
        Get the set of all vertices of the graph.

        Each vertex in the graph is identified by a unique non null hashable object and the returned set is a set of all these identifiers.

        The Graph object does not expose an explicit method to get the number of vertices, but it can accessed using this method by g.vertices().size().

        In an Index graph, the set of vertices are always (0,1,2, ...,verticesNum-1).

        Returns:
        a set containing all vertices of the graph
      • edges

        public final com.jgalgo.graph.GraphElementSet edges()
        Description copied from interface: IndexGraph
        Get the set of all edges of the graph.

        Each edge in the graph is identified by a unique non null hashable object, and the returned set is a set of all these identifiers.

        The Graph object does not expose an explicit method to get the number of edges, but it can accessed using this method by g.edges().size().

        In an Index graph, the set of edges are always (0,1,2, ...,edgesNum-1).

        Returns:
        a set containing all edges of the graph
      • addVertex

        public int addVertex()
        Description copied from interface: IndexGraph
        Add a new vertex to the graph.

        The graph implementation will choose a new int identifier which is not currently used as one of the graph edges, and will return it as the new vertex ID.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Returns:
        the new vertex identifier
      • removeVertex

        public final void removeVertex​(int vertex)
        Description copied from interface: IndexGraph
        Remove a vertex and all its edges from the graph.

        After removing a vertex, the graph implementation may swap and rename vertices to maintain its invariants. Theses renames can be subscribed using IndexGraph.addVertexRemoveListener(IndexRemoveListener).

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Parameters:
        vertex - the vertex identifier to remove
      • removeEdge

        public final void removeEdge​(int edge)
        Description copied from interface: IndexGraph
        Remove an edge from the graph.

        After removing an edge, the graph implementation may swap and rename edges to maintain its invariants. Theses renames can be subscribed using IndexGraph.addEdgeRemoveListener(IndexRemoveListener).

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Parameters:
        edge - the edge identifier
      • clear

        public void clear()
        Description copied from interface: IndexGraph
        Clear the graph completely by removing all vertices and edges.

        This function might be used to reuse an already allocated graph object.

        Note that this function also clears any weights associated with the vertices or edges.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

      • getVerticesIWeights

        public <T,​WeightsT extends IWeights<T>> WeightsT getVerticesIWeights​(String key)
        Description copied from interface: IntGraph
        Get the vertices weights of some key.

        See IWeights for a complete documentation of the weights containers.

        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as IWeightsInt, IWeightsDouble ect.
        Parameters:
        key - key of the weights
        Returns:
        vertices weights of the key, or null if no container found with the specified key
      • getVerticesWeightsKeys

        public Set<String> getVerticesWeightsKeys()
        Description copied from interface: Graph
        Get the keys of all the associated vertices weights.

        See Weights for a complete documentation of the weights containers.

        Returns:
        the keys of all the associated vertices weights
      • removeVerticesWeights

        public void removeVerticesWeights​(String key)
        Description copied from interface: IndexGraph
        Remove a weight type associated with the vertices of the graph.

        See Weights for a complete documentation of the weights containers.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Parameters:
        key - the key of the weights
      • getEdgesIWeights

        public <T,​WeightsT extends IWeights<T>> WeightsT getEdgesIWeights​(String key)
        Description copied from interface: IntGraph
        Get the edges weights of some key.

        See IWeights for a complete documentation of the weights containers.

        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as IWeightsInt, IWeightsDouble ect.
        Parameters:
        key - key of the weights
        Returns:
        edges weights of the key, or null if no container found with the specified key
      • getEdgesWeightsKeys

        public Set<String> getEdgesWeightsKeys()
        Description copied from interface: Graph
        Get the keys of all the associated edges weights.

        See Weights for a complete documentation of the weights containers.

        Returns:
        the keys of all the associated edges weights
      • removeEdgesWeights

        public void removeEdgesWeights​(String key)
        Description copied from interface: IndexGraph
        Remove a weight type associated with the edges of the graph.

        See Weights for a complete documentation of the weights containers.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Parameters:
        key - the key of the weights
      • addVerticesWeights

        public <T,​WeightsT extends Weights<Integer,​T>> WeightsT addVerticesWeights​(String key,
                                                                                               Class<? super T> type,
                                                                                               T defVal)
        Description copied from interface: IndexGraph
        Add a new weights container associated with the vertices of this graph with default value.

        The created weights will be bounded to this graph, and will be updated when the graph is updated. To create an external weights container, for example in cases the graph is a user input we are not allowed to modify it, use Weights.createExternalVerticesWeights(Graph, Class, Object).

         
         Graph<String, Int> g = ...;
         g.newVertex("Alice");
         g.newVertex("Bob");
         g.newVertex("Charlie");
        
         Weights<String> names = g.addVerticesWeights("name", String.class, "Unknown");
         names.set("Alice", "Miller");
         names.set("Bob", "Jones");
        
         assert "Miller".equals(names.get("Alice"))
         assert "Jones".equals(names.get("Bob"))
         assert "Unknown".equals(names.get("Charlie"))
         

        See Weights for a complete documentation of the weights containers.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as WeightsInt, WeightsDouble ect.
        Parameters:
        key - key of the weights
        type - the type of the weights, used for primitive types weights
        defVal - default value use for the weights container
        Returns:
        a new weights container
      • addEdgesWeights

        public <T,​WeightsT extends Weights<Integer,​T>> WeightsT addEdgesWeights​(String key,
                                                                                            Class<? super T> type,
                                                                                            T defVal)
        Description copied from interface: IndexGraph
        Add a new weights container associated with the edges of this graph with default value.

        The created weights will be bounded to this graph, and will be updated when the graph is updated. To create an external weights container, for example in cases the graph is a user input we are not allowed to modify it, use Weights.createExternalEdgesWeights(Graph, Class, Object).

         
         Graph<String, Integer> g = ...;
         g.addVertex("Berlin");
         g.addVertex("Leipzig");
         g.addVertex("Dresden");
         g.addEdge("Berlin", "Leipzig", 9);
         g.addEdge("Berlin", "Dresden", 13);
         g.addEdge("Dresden", "Leipzig", 14);
        
         Weights<String> roadTypes = g.addEdgesWeights("roadType", String.class, "Unknown");
         roadTypes.set(9, "Asphalt");
         roadTypes.set(13, "Gravel");
        
         assert "Asphalt".equals(names.get(9))
         assert "Gravel".equals(names.get(13))
         assert "Unknown".equals(names.get(14))
         

        See Weights for a complete documentation of the weights containers.

        If this index graph object was obtained from a regular Graph using Graph.indexGraph(), this method should not be called. Use the original graph instead.

        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as WeightsInt, WeightsDouble ect.
        Parameters:
        key - key of the weights
        type - the type of the weights, used for primitive types weights
        defVal - default value use for the weights container
        Returns:
        a new weights container
      • addVertexRemoveListener

        public void addVertexRemoveListener​(IndexRemoveListener listener)
        Description copied from interface: IndexGraph
        Adds a listener that will be called each time a vertex remove or swap is performed.

        An IndexGraph may rename vertices during its lifetime to maintain the invariant that all vertices are identified by 0,1,2,...,verticesNum-1. This method can be used to track these changes, by registering a listener that will be invoked each time such a rename is performed.

        If a vertex is removed with the last index (verticesNum-1), the vertex can simply be removed. Otherwise, the vertex will be swapped with the last vertex and then removed. In both cases, the listener will be called.

        Parameters:
        listener - a remove listener that will be called each time a vertex remove or swap is performed
      • addEdgeRemoveListener

        public void addEdgeRemoveListener​(IndexRemoveListener listener)
        Description copied from interface: IndexGraph
        Adds a listener that will be called each time a edge swap is performed.

        An IndexGraph may rename edges during its lifetime to maintain the invariant that all edges are identified by 0,1,2,...,edgesNum-1. This method can be used to track these changes, by registering a listener that will be invoked each time such a rename is performed.

        If an edge is removed with the last index (edgesNum-1), the edge can simply be removed. Otherwise, the edge will be swapped with the last edge and then removed. In both cases, the listener will be called.

        Parameters:
        listener - a remove listener that will be called each time a edge remove or swap is performed
      • isDirected

        public boolean isDirected()
        Description copied from interface: Graph
        Checks whether the graph is directed.
        Specified by:
        isDirected in interface Graph<Integer,​Integer>
        Returns:
        true if the graph is directed, else false.
      • isAllowSelfEdges

        public boolean isAllowSelfEdges()
        Description copied from interface: Graph
        Checks whether self edges are supported.

        Self edges are edges with the same source and target, namely a vertex with an edge to itself.

        Specified by:
        isAllowSelfEdges in interface Graph<Integer,​Integer>
        Returns:
        true if the graph support self edges, else false.
      • isAllowParallelEdges

        public boolean isAllowParallelEdges()
        Description copied from interface: Graph
        Checks whether parallel edges are supported.

        Parallel edges are multiple edges with identical source and target.

        Specified by:
        isAllowParallelEdges in interface Graph<Integer,​Integer>
        Returns:
        true if the graph support parallel edges, else false.
      • getEdges

        public IEdgeSet getEdges​(int source,
                                 int target)
        Description copied from interface: IntGraph
        Get the edges whose source is source and target is target.
        Specified by:
        getEdges in interface IntGraph
        Parameters:
        source - a source vertex
        target - a target vertex
        Returns:
        all the edges whose source is source and target is target
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object