Interface IndexIdMap<K>

  • Type Parameters:
    K - the elements (vertices/edges) type
    All Known Subinterfaces:
    IndexIntIdMap

    public interface IndexIdMap<K>
    A mapping between Graph IDs to IndexGraph indices.

    A regular graph contains vertices and edges which are identified by a fixed hashable identifiers. An IndexGraph view is provided by the Graph.indexGraph() method, which is a graph in which all methods are accessed with indices rather than fixed IDs. This interface maps between the indices and the fixed IDs of the graph vertices or edges.

    Note that the mapping may change during the graph lifetime, as vertices and edges are added and removed from the graph, and a regular graph IDs are fixed, while a index graph indices are always (0,1,2, ...,verticesNum-1) and (0,1,2, ...,edgesNum-1). The mapping object will be updated automatically in such cases.

    The mapping interface is used for both vertices and edges, and we use a unify term element in the documentation to describe both of them (vertex or edge). If the mapping was obtained by Graph.indexGraphVerticesMap() it will map between vertices IDs and indices, and if it was obtained by Graph.indexGraphEdgesMap() it will map between edges IDs and indices.

    Author:
    Barak Ugav
    See Also:
    IndexGraph
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int idToIndex​(K id)
      Get the index of an element by its identifier.
      int idToIndexIfExist​(K id)
      Get the index of an element by its identifier if it exists, or -1 if it doesn't.
      K indexToId​(int index)
      Get the identifier of an element by its index.
      K indexToIdIfExist​(int index)
      Get the identifier of an element by its index if it exists, or null if it doesn't.
    • Method Detail

      • indexToId

        K indexToId​(int index)
        Get the identifier of an element by its index.

        Whether this method maps vertices or edges depends if the mapping object was obtained by Graph.indexGraphVerticesMap() or Graph.indexGraphEdgesMap().

        Parameters:
        index - an index of an element (vertex/edge)
        Returns:
        the identifier of the element
        Throws:
        IndexOutOfBoundsException - if index is not in range [, elementsNum) where elementsNum is the number of either vertices or edges, depending on the context
      • indexToIdIfExist

        K indexToIdIfExist​(int index)
        Get the identifier of an element by its index if it exists, or null if it doesn't.

        Whether this method maps vertices or edges depends if the mapping object was obtained by Graph.indexGraphVerticesMap() or Graph.indexGraphEdgesMap().

        Parameters:
        index - the index of an element (vertex/edge)
        Returns:
        the identifier of the element, or null if there is not such element
      • idToIndex

        int idToIndex​(K id)
        Get the index of an element by its identifier.

        Whether this method maps vertices or edges depends if the mapping object was obtained by Graph.indexGraphVerticesMap() or Graph.indexGraphEdgesMap().

        Parameters:
        id - an identifier of an element (vertex/edge)
        Returns:
        the index of the element
        Throws:
        NoSuchVertexException - if this map maps vertices to ids and id is not a valid identifier of a vertex
        NoSuchEdgeException - if this map maps edges to ids and id is not a valid identifier of an edge
      • idToIndexIfExist

        int idToIndexIfExist​(K id)
        Get the index of an element by its identifier if it exists, or -1 if it doesn't.

        Whether this method maps vertices or edges depends if the mapping object was obtained by Graph.indexGraphVerticesMap() or Graph.indexGraphEdgesMap().

        Parameters:
        id - an identifier of an element (vertex/edge)
        Returns:
        the index of the element, or -1 if there is not such element