Interface IndexGraphBuilder

    • Method Detail

      • addVertex

        int addVertex()
        Add a new vertex to the graph.

        The builder will choose identifier not used for any existing vertex, and will return it. It is also possible to add a new vertex and choose its identifier by using IntGraphBuilder.addVertex(int). Only one of IntGraphBuilder.addVertex() and IntGraphBuilder.addVertex(int) can be used during the construction of a graph.

        As the built graph is an Index graph, the vertices must be 0,1,2,...,verticesNum-1 and user-chosen IDs are not supported. A new vertex will be assigned ID of value vertices().size().

        Specified by:
        addVertex in interface IntGraphBuilder
        Returns:
        the new vertex identifier
      • addEdge

        int addEdge​(int source,
                    int target)
        Add a new edge to the graph.

        The builder will choose identifier not used for any existing edge, and will return it. It is also possible to add a new edge and choose its identifier by using IntGraphBuilder.addEdge(int, int, int). Only one of IntGraphBuilder.addEdge(int, int) and IntGraphBuilder.addEdge(int, int, int) can be used during the construction of a graph.

        As the built graph is an Index graph, the edges must be 0,1,2,...,edgesNum-1. A new edge will be assigned ID of value edges().size().

        It is possible to construct a graph by inserting the edges in a different order than their indices (IDs), by using addEdge(int, int, int) in which the ID of the inserted edge is specified along with the source and target vertices. If this method is used, the set of edges will be validated when a new graph is created, and it must be equal 0,1,2,...,edgesNum-1.

        Specified by:
        addEdge in interface IntGraphBuilder
        Parameters:
        source - the source vertex of the new edge
        target - the target vertex of the new edge
        Returns:
        the new edge identifier
      • addEdge

        void addEdge​(int source,
                     int target,
                     int edge)
        Add a new edge to the graph, with user-chosen identifier.

        This function is similar to IntGraphBuilder.addEdge(int, int), but let the user to choose the identifier of the new edge. Only one of IntGraphBuilder.addEdge(int, int) and IntGraphBuilder.addEdge(int, int, int) can be used during the construction of a graph.

        As the built graph is an Index graph, the edges must be 0,1,2,...,edgesNum-1. This constraint is validated when the graph is actually created by the builder.

        Specified by:
        addEdge in interface IntGraphBuilder
        Parameters:
        source - the source vertex of the new edge
        target - the target vertex of the new edge
        edge - the identifier of the new edge
      • reIndexAndBuild

        IndexGraphBuilder.ReIndexedGraph reIndexAndBuild​(boolean reIndexVertices,
                                                         boolean reIndexEdges)
        Re-Index the vertices/edges and build a new immutable graph with the new indexing.

        Re-indexing is the operation of assigning new indices to the vertices/edges. By re-indexing the vertices/edges, the performance of accessing/iterating over the graph vertices/edges may increase, for example if a more cache friendly indexing exists.

        Note that this method is not required to re-index the vertices (edges) if reIndexVertices (reIndexEdges) is true, it is simply allowed to. Whether or not a re-indexing was performed can be checked via the IndexGraphBuilder.ReIndexedGraph return value.

        Parameters:
        reIndexVertices - if true, the implementation is allowed to (note that it is not required) to re-index the vertices of the graph. If false, the original vertices identifiers are used. Whether or not re-indexing was performed can be checked via IndexGraphBuilder.ReIndexedGraph.verticesReIndexing().
        reIndexEdges - if true, the implementation is allowed to (note that it is not required) to re-index the edges of the graph. If false, the original edges identifiers are used. Whether or not re-indexing was performed can be checked via IndexGraphBuilder.ReIndexedGraph.edgesReIndexing().
        Returns:
        the re-indexed immutable graph, along with the re-indexing mapping to the original indices
      • reIndexAndBuildMutable

        IndexGraphBuilder.ReIndexedGraph reIndexAndBuildMutable​(boolean reIndexVertices,
                                                                boolean reIndexEdges)
        Re-Index the vertices/edges and build a new mutable graph with the new indexing.

        Re-indexing is the operation of assigning new indices to the vertices/edges. By re-indexing the vertices/edges, the performance of accessing/iterating over the graph vertices/edges may increase, for example if a more cache friendly indexing exists.

        Note that this method is not required to re-index the vertices (edges) if reIndexVertices (reIndexEdges) is true, it is simply allowed to. Whether or not a re-indexing was performed can be checked via the IndexGraphBuilder.ReIndexedGraph return value.

        Parameters:
        reIndexVertices - if true, the implementation is allowed to (note that it is not required) to re-index the vertices of the graph. If false, the original vertices identifiers are used. Whether or not re-indexing was performed can be checked via IndexGraphBuilder.ReIndexedGraph.verticesReIndexing().
        reIndexEdges - if true, the implementation is allowed to (note that it is not required) to re-index the edges of the graph. If false, the original edges identifiers are used. Whether or not re-indexing was performed can be checked via IndexGraphBuilder.ReIndexedGraph.edgesReIndexing().
        Returns:
        the re-indexed mutable graph, along with the re-indexing mapping to the original indices
      • newUndirected

        static IndexGraphBuilder newUndirected()
        Create a new builder that builds undirected graphs.
        Returns:
        a new empty builder for undirected graphs
      • newDirected

        static IndexGraphBuilder newDirected()
        Create a new builder that builds directed graphs.
        Returns:
        a new empty builder for directed graphs
      • newFrom

        static IndexGraphBuilder newFrom​(IndexGraph g)
        Create a new builder initialized with an existing graph vertices and edges, without copying the weights.

        If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.

        Parameters:
        g - a graph
        Returns:
        a builder initialized with the given graph vertices and edges, without the original graph vertices/edges weights.
      • newFrom

        static IndexGraphBuilder newFrom​(IndexGraph g,
                                         boolean copyWeights)
        Create a new builder initialized with an existing graph vertices and edges, with/without copying the weights.

        If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.

        Parameters:
        g - a graph
        copyWeights - if true, the weights of the vertices and edges will be copied to the new graph
        Returns:
        a builder initialized with the given graph vertices and edges, with/without the original graph vertices/edges weights.