Class MutableIntAttributed16BitIndexedBidiGraph

java.lang.Object
org.jhotdraw8.graph.MutableIntAttributed16BitIndexedBidiGraph
All Implemented Interfaces:
IndexedBidiGraph, IndexedDirectedGraph, IntAttributedIndexedBidiGraph, IntAttributedIndexedDirectedGraph, MutableIndexedBidiGraph

public class MutableIntAttributed16BitIndexedBidiGraph extends Object implements MutableIndexedBidiGraph, IntAttributedIndexedBidiGraph
A mutable indexed bi-directional graph.

Supports up to 2^16 - 1 vertices.

This implementation uses large contiguous arrays. Each row occupies maxArity + 1 elements in the array for the arrows.

If the arity of the vertices is unevenly distributed, a dfs- or bfs-search is likely to encounter a different cash line or page for every vertex.

XXX delete me, this representation is inefficient

  • Constructor Details

    • MutableIntAttributed16BitIndexedBidiGraph

      public MutableIntAttributed16BitIndexedBidiGraph(int vertexCapacity, int maxArity)
      Creates a new instance.
      Parameters:
      vertexCapacity - the initial vertex capacity
      maxArity - the maximal number of arrows per vertex
  • Method Details

    • clear

      public void clear()
      Removes all vertices and all arrows.
    • addArrowAsInt

      public void addArrowAsInt(int v, int u)
      Description copied from interface: MutableIndexedBidiGraph
      Adds an arrow from vertex 'v' to vertex 'u' with arrow data 0.
      Specified by:
      addArrowAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
      u - index of vertex 'u'
    • addArrowAsInt

      public void addArrowAsInt(int v, int u, int arrowData)
      Description copied from interface: MutableIndexedBidiGraph
      Adds an arrow from vertex 'v' to vertex 'u'.
      Specified by:
      addArrowAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
      u - index of vertex 'u'
      arrowData - the arrow data
    • addVertexAsInt

      public void addVertexAsInt()
      Description copied from interface: MutableIndexedBidiGraph
      Adds a vertex to the graph.
      Specified by:
      addVertexAsInt in interface MutableIndexedBidiGraph
    • addVertexAsInt

      public void addVertexAsInt(int v)
      Description copied from interface: MutableIndexedBidiGraph
      Adds a vertex at the specified index to the graph.
      Specified by:
      addVertexAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
    • findIndexOfNextAsInt

      public int findIndexOfNextAsInt(int v, int u)
      Description copied from interface: IndexedDirectedGraph
      Returns the index of vertex b.
      Specified by:
      findIndexOfNextAsInt in interface IndexedDirectedGraph
      Parameters:
      v - a vertex
      u - another vertex
      Returns:
      index of vertex b. Returns a value < 0 if b is not a next vertex of a.
    • findIndexOfPrevAsInt

      public int findIndexOfPrevAsInt(int v, int u)
      Description copied from interface: IndexedBidiGraph
      Returns the index of the arrow from v to u in the list of next-vertices from v.
      Specified by:
      findIndexOfPrevAsInt in interface IndexedBidiGraph
      Parameters:
      v - vertex v
      u - vertex u
      Returns:
      index of vertex u in the list of next-vertices from v. Returns a value < 0 if u is not in the list.
    • getArrowCount

      public int getArrowCount()
      Description copied from interface: IndexedDirectedGraph
      Returns the number of arrows.
      Specified by:
      getArrowCount in interface IndexedDirectedGraph
      Returns:
      arrow count
    • getNextAsInt

      public int getNextAsInt(int v, int i)
      Description copied from interface: IndexedDirectedGraph
      Returns the i-th next vertex of v.
      Specified by:
      getNextAsInt in interface IndexedDirectedGraph
      Parameters:
      v - a vertex index
      i - the index of the desired next vertex, i ∈ {0, ..., getNextCount(v) -1 }.
      Returns:
      the vertex index of the i-th next vertex of v.
    • getNextCount

      public int getNextCount(int v)
      Description copied from interface: IndexedDirectedGraph
      Returns the number of next vertices of v.
      Specified by:
      getNextCount in interface IndexedDirectedGraph
      Parameters:
      v - a vertex
      Returns:
      the number of next vertices of v.
    • getPrevAsInt

      public int getPrevAsInt(int v, int i)
      Description copied from interface: IndexedBidiGraph
      Returns the i-th previous vertex of v.
      Specified by:
      getPrevAsInt in interface IndexedBidiGraph
      Parameters:
      v - index of vertex v
      i - index of ingoing arrow
      Returns:
      the vertex index of the ingoing arrow
    • getPrevCount

      public int getPrevCount(int v)
      Description copied from interface: IndexedBidiGraph
      Returns the number of direct predecessor vertices of v.
      Specified by:
      getPrevCount in interface IndexedBidiGraph
      Parameters:
      v - index of vertex v
      Returns:
      the number of next vertices of v.
    • getVertexCount

      public int getVertexCount()
      Description copied from interface: IndexedDirectedGraph
      Returns the number of vertices V.
      Specified by:
      getVertexCount in interface IndexedDirectedGraph
      Returns:
      vertex count
    • nextVerticesEnumerator

      public @NonNull Enumerator.OfInt nextVerticesEnumerator(int v)
      Description copied from interface: IndexedDirectedGraph
      Returns the direct successor vertices of the specified vertex.
      Specified by:
      nextVerticesEnumerator in interface IndexedDirectedGraph
      Parameters:
      v - a vertex index
      Returns:
      a collection view on the direct successor vertices of vertex
    • prevVerticesEnumerator

      public @NonNull Enumerator.OfInt prevVerticesEnumerator(int v)
      Description copied from interface: IndexedBidiGraph
      Returns the direct successor vertices of the specified vertex.
      Specified by:
      prevVerticesEnumerator in interface IndexedBidiGraph
      Parameters:
      v - index of vertex v
      Returns:
      a collection view on the direct successor vertices of vertex
    • removeAllPrevAsInt

      public void removeAllPrevAsInt(int v)
      Description copied from interface: MutableIndexedBidiGraph
      Removes all arrows ending at the specified vertex.
      Specified by:
      removeAllPrevAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
    • removeAllNextAsInt

      public void removeAllNextAsInt(int v)
      Description copied from interface: MutableIndexedBidiGraph
      Removes all arrows starting at the specified vertex.
      Specified by:
      removeAllNextAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
    • removeNextAsInt

      public void removeNextAsInt(int v, int index)
      Description copied from interface: MutableIndexedBidiGraph
      Removes the i-th arrow starting at vertex 'v'
      Specified by:
      removeNextAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
      index - the index of the arrow starting at 'v'
    • removePrevAsInt

      public void removePrevAsInt(int vidx, int i)
      Description copied from interface: MutableIndexedBidiGraph
      Removes the i-th arrow ending at vertex 'v'
      Specified by:
      removePrevAsInt in interface MutableIndexedBidiGraph
      Parameters:
      vidx - index of vertex 'v'
      i - the index of the arrow ending at 'v'
    • removeVertexAsInt

      public void removeVertexAsInt(int v)
      Description copied from interface: MutableIndexedBidiGraph
      Removes vertex 'v'
      Specified by:
      removeVertexAsInt in interface MutableIndexedBidiGraph
      Parameters:
      v - index of vertex 'v'
    • setVertexAsInt

      public void setVertexAsInt(int vidx, int data)
      Sets the vertex data for the specified vertex.
      Parameters:
      vidx - the index of the vertex
      data - the vertex data
    • getNextArrowAsInt

      public int getNextArrowAsInt(int v, int i)
      Description copied from interface: IndexedDirectedGraph
      Returns the i-th next arrow of v.
      Specified by:
      getNextArrowAsInt in interface IndexedDirectedGraph
      Specified by:
      getNextArrowAsInt in interface IntAttributedIndexedDirectedGraph
      Parameters:
      v - a vertex index
      i - the index of the desired arrow, i ∈ {0, ..., getNextCount(v) -1 }.
      Returns:
      the arrow data of the i-th next vertex of v.
    • getPrevArrowAsInt

      public int getPrevArrowAsInt(int v, int i)
      Description copied from interface: IndexedBidiGraph
      Returns the arrow data of the i-th ingoing arrow to v.
      Specified by:
      getPrevArrowAsInt in interface IndexedBidiGraph
      Parameters:
      v - index of vertex v
      i - index of ingoing arrow
      Returns:
      the arrow data of the ingoing arrow
    • getVertexDataAsInt

      public int getVertexDataAsInt(int vidx)
      Description copied from interface: IntAttributedIndexedDirectedGraph
      Returns the data of the specified vertex.
      Specified by:
      getVertexDataAsInt in interface IntAttributedIndexedDirectedGraph
      Parameters:
      vidx - a vertex
      Returns:
      the vertex data
    • getVertexDataFromNextAsInt

      public int getVertexDataFromNextAsInt(int vidx)
    • getVertexDataFromPrevAsInt

      public int getVertexDataFromPrevAsInt(int vidx)
    • seachNextVerticesAsInt

      public @NonNull Enumerator.OfInt seachNextVerticesAsInt(int vidx, boolean dfs)
      Returns a breadth first spliterator that starts at the specified vertex.
      Parameters:
      vidx - the index of the vertex
      dfs - whether to search depth-first instead of breadth-first
      Returns:
      the spliterator
    • seachNextVerticesAsInt

      public @NonNull Enumerator.OfInt seachNextVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs)
    • searchPrevVerticesAsInt

      public @NonNull Enumerator.OfInt searchPrevVerticesAsInt(int vidx, boolean dfs)
      Returns a backward breadth first spliterator that starts at the specified vertex.
      Parameters:
      vidx - the index of the vertex
      dfs -
      Returns:
      the spliterator
    • searchPrevVerticesAsInt

      public @NonNull Enumerator.OfInt searchPrevVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs)
    • searchNextVerticesWithVertexData

      public @NonNull Enumerator.OfLong searchNextVerticesWithVertexData(int vidx, boolean dfs)
      Returns a breadth first spliterator that starts at the specified vertex.
      Parameters:
      vidx - the index of the vertex
      dfs -
      Returns:
      the spliterator contains the vertex data in the 32 high-bits and the vertex index in the 32 low-bits of the long.
    • searchNextVerticesWithVertexData

      public @NonNull Enumerator.OfLong searchNextVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs)
    • searchPrevVerticesWithVertexData

      public @NonNull Enumerator.OfLong searchPrevVerticesWithVertexData(int vidx, boolean dfs)
      Returns a backward breadth first spliterator that starts at the specified vertex.
      Parameters:
      vidx - the index of the vertex
      dfs -
      Returns:
      the spliterator contains the vertex data in the 32 high-bits and the vertex index in the 32 low-bits of the long.
    • searchPrevVerticesWithVertexData

      public @NonNull Enumerator.OfLong searchPrevVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs)