Class ImmutableAttributed32BitIndexedBidiGraph<V,A>
- Type Parameters:
V- the vertex data typeA- the arrow data type
- All Implemented Interfaces:
AttributedIndexedBidiGraph<V,,A> AttributedIndexedDirectedGraph<V,,A> BareBidiGraph<V,,A> BareDirectedGraph<V,,A> BareDirectedVertexGraph<V>,BidiGraph<V,,A> DirectedGraph<V,,A> IndexedBidiGraph,IndexedDirectedGraph
Supports up to 2^31 - 1 vertices.
Uses a representation that is similar to a compressed row storage for
matrices (CRS). A bidirectional graph is represented with 7 arrays:
nextOffset, next, nextArrows, prevOffset,
prev, prevArrows, and vertices.
nextOffset- Holds for each vertex
v, the offset into the arraysnext, andnextArrows. The data for vertexvcan be found in these arrays in the elements fromnextOffset[v](inclusive) tonextOffset[v + 1](exclusive). next- Holds for each arrow from a vertex
vto a vertexuthe index ofu. nextArrows- Holds for each arrow from a vertex
vto a vertexuthe data associated to the arrow. prevOffset,next,nextArrows- These arrays have the same structure as
nextOffset,next,nextArrowsbut they they store for a vertexvthe data for ingoing arrows from a vertexuto the vertexv vertices- Holds for each vertex
vthe data associated to the vertex.
- Author:
- Werner Randelshofer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int @NonNull []Holds the indices to the next vertices.Holds the arrow objects.protected final int @NonNull []Holds offsets into thenexttable and thenextArrowstable.protected final int @NonNull []protected final int @NonNull []Maps vertices the vertex indices.Holds the vertex objects. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance from the specified graph.Creates a new instance from the specified graph. -
Method Summary
Modifier and TypeMethodDescriptiongetArrow(int index) Returns the data of the specified arrow.getArrow(int vertex, int index) intReturns the number of arrows.protected intgetArrowIndex(int vi, int i) Returns the next vertex associated with the specified vertex and outgoing arrow index.getNextArrow(int v, int i) Returns the specified successor (next) arrow of the specified vertex.getNextArrow(@NonNull V v, int i) Returns the arrow data associated with the specified vertex and outgoing arrow index.intgetNextArrowAsInt(int v, int i) Returns thei-th next arrow ofv.intgetNextAsInt(int v, int i) Returns thei-th next vertex ofv.intgetNextCount(int v) Returns the number of next vertices of v.intReturns the number of next vertices at the specified vertex.Returns the previous vertex associated with the specified vertex and incoming arrow index.getPrevArrow(int vi, int i) Returns the specified predecessor (previous) arrow of the specified vertex.getPrevArrow(@NonNull V v, int i) Returns the arrow data associated with the specified vertex and the specified incoming arrow index.intgetPrevArrowAsInt(int v, int i) Returns the arrow data of thei-th ingoing arrow tov.intgetPrevAsInt(int v, int i) Returns thei-th previous vertex ofv.intgetPrevCount(int v) Returns the number of direct predecessor vertices of v.intgetPrevCount(@NonNull V vertex) Returns the number of previous vertices at the specified vertex.getVertex(int index) Returns the data of the specified vertex.intReturns the number of verticesV.intgetVertexIndex(V vertex) Returns the index of the vertex.Returns all vertices.nextVerticesEnumerator(int v) Returns the direct successor vertices of the specified vertex.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.graph.AttributedIndexedBidiGraph
getPrevIntEntriesMethods inherited from interface org.jhotdraw8.graph.AttributedIndexedDirectedGraph
getNextIntEntriesMethods inherited from interface org.jhotdraw8.graph.BidiGraph
findIndexOfPrev, getPrevArc, getPrevArcs, getPrevArrows, getPrevVertices, isPrev, searchPrevVertices, searchPrevVerticesMethods inherited from interface org.jhotdraw8.graph.DirectedGraph
findArrow, findIndexOfNext, getArrows, getArrows, getNextArc, getNextArcs, getNextArrows, getNextVertices, isNext, searchNextVertices, searchNextVerticesMethods inherited from interface org.jhotdraw8.graph.IndexedBidiGraph
findIndexOfPrevAsInt, isPrevAsInt, prevVerticesEnumeratorMethods inherited from interface org.jhotdraw8.graph.IndexedDirectedGraph
findIndexOfNextAsInt, isNextAsInt
-
Field Details
-
next
Holds the indices to the next vertices.The indices are stored in consecutive runs for each vertex, starting at the offset given by
nextOffset.Given vertex index
vi < nextOffset.length - 1
then
offset = nextOffset[vi]count = nextOffset[vi+1] - offsetGiven vertex index
vi == nextOffset.length - 1
then
offset = nextOffset[vi]count = nextOffset.length - offset -
prev
-
nextOffset
Holds offsets into thenexttable and thenextArrowstable.Given vertex index
vi,
nextOffset[vi]yields the offsetaiin the tablesnexttable and thenextArrows.Given vertex index
vi < nextOffset.length - 1,
nextOffset[vi+1]) - nextOffset[vi]yields the number of outgoing arrows of that vertex.Given vertex index
vi == nextOffset.length - 1,
nextOffset.length - nextOffset[vi]yields the number of outgoing arrows of that vertex. -
prevOffset
-
nextArrows
Holds the arrow objects.The arrows are stored in consecutive runs for each vertex, starting at the offset given by
nextOffset.See
next. -
prevArrows
-
vertices
Holds the vertex objects.Given vertex index
vi,
vertices[vi|yields the vertexv. -
vertexToIndexMap
Maps vertices the vertex indices.Given vertex
v,
vertexToIndexMap.get(v)yields the vertex indexvi.
-
-
Constructor Details
-
ImmutableAttributed32BitIndexedBidiGraph
Creates a new instance from the specified graph.- Parameters:
graph- a graph
-
ImmutableAttributed32BitIndexedBidiGraph
Creates a new instance from the specified graph.- Parameters:
graph- a graph
-
-
Method Details
-
getArrow
Description copied from interface:AttributedIndexedDirectedGraphReturns the data of the specified arrow.- Specified by:
getArrowin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
index- index of arrow- Returns:
- arrow data
-
getArrow
-
getArrowCount
public int getArrowCount()Description copied from interface:IndexedDirectedGraphReturns the number of arrows.- Specified by:
getArrowCountin interfaceDirectedGraph<V,A> - Specified by:
getArrowCountin interfaceIndexedDirectedGraph- Returns:
- arrow count
-
getArrowIndex
protected int getArrowIndex(int vi, int i) -
getNext
Description copied from interface:BareDirectedVertexGraphReturns the next vertex associated with the specified vertex and outgoing arrow index.- Specified by:
getNextin interfaceBareDirectedVertexGraph<V>- Parameters:
v- a vertexi- index of outgoing arrow- Returns:
- the next vertex
- See Also:
-
getNextArrow
Description copied from interface:AttributedIndexedDirectedGraphReturns the specified successor (next) arrow of the specified vertex.- Specified by:
getNextArrowin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
v- a vertexi- index of next arrow- Returns:
- the specified arrow
-
getNextArrow
Description copied from interface:BareDirectedGraphReturns the arrow data associated with the specified vertex and outgoing arrow index.- Specified by:
getNextArrowin interfaceBareDirectedGraph<V,A> - Parameters:
v- a vertexi- index of outgoing arrow- Returns:
- the next arrow data
- See Also:
-
getNextAsInt
public int getNextAsInt(int v, int i) Description copied from interface:IndexedDirectedGraphReturns thei-th next vertex ofv.- Specified by:
getNextAsIntin interfaceIndexedDirectedGraph- Parameters:
v- a vertex indexi- the index of the desired next vertex,i ∈ {0, ..., getNextCount(v) -1 }.- Returns:
- the vertex index of the i-th next vertex of v.
-
getNextArrowAsInt
public int getNextArrowAsInt(int v, int i) Description copied from interface:IndexedDirectedGraphReturns thei-th next arrow ofv.- Specified by:
getNextArrowAsIntin interfaceIndexedDirectedGraph- Parameters:
v- a vertex indexi- the index of the desired arrow,i ∈ {0, ..., getNextCount(v) -1 }.- Returns:
- the arrow data of the i-th next vertex of v.
-
getNextCount
public int getNextCount(int v) Description copied from interface:IndexedDirectedGraphReturns the number of next vertices of v.- Specified by:
getNextCountin interfaceIndexedDirectedGraph- Parameters:
v- a vertex- Returns:
- the number of next vertices of v.
-
getNextCount
Description copied from interface:BareDirectedVertexGraphReturns the number of next vertices at the specified vertex.This number is the same as the number of outgoing arrows at the specified vertex.
- Specified by:
getNextCountin interfaceBareDirectedVertexGraph<V>- Parameters:
v- a vertex- Returns:
- the number of next vertices
-
getPrev
Description copied from interface:BareBidiGraphReturns the previous vertex associated with the specified vertex and incoming arrow index.- Specified by:
getPrevin interfaceBareBidiGraph<V,A> - Parameters:
vertex- a vertexi- index of incoming arrow- Returns:
- the previous vertex
- See Also:
-
getPrevArrow
Description copied from interface:AttributedIndexedBidiGraphReturns the specified predecessor (previous) arrow of the specified vertex.- Specified by:
getPrevArrowin interfaceAttributedIndexedBidiGraph<V,A> - Parameters:
vi- a vertexi- index of next arrow- Returns:
- the specified arrow
-
getPrevArrow
Description copied from interface:BareBidiGraphReturns the arrow data associated with the specified vertex and the specified incoming arrow index.- Specified by:
getPrevArrowin interfaceBareBidiGraph<V,A> - Parameters:
v- a vertexi- index of incoming arrow- Returns:
- the arrow
- See Also:
-
getPrevAsInt
public int getPrevAsInt(int v, int i) Description copied from interface:IndexedBidiGraphReturns thei-th previous vertex ofv.- Specified by:
getPrevAsIntin interfaceIndexedBidiGraph- Parameters:
v- index of vertex vi- index of ingoing arrow- Returns:
- the vertex index of the ingoing arrow
-
getPrevArrowAsInt
public int getPrevArrowAsInt(int v, int i) Description copied from interface:IndexedBidiGraphReturns the arrow data of thei-th ingoing arrow tov.- Specified by:
getPrevArrowAsIntin interfaceIndexedBidiGraph- Parameters:
v- index of vertex vi- index of ingoing arrow- Returns:
- the arrow data of the ingoing arrow
-
getPrevCount
Description copied from interface:BareBidiGraphReturns the number of previous vertices at the specified vertex.This number is the same as the number of incoming arrows at the specified vertex.
- Specified by:
getPrevCountin interfaceBareBidiGraph<V,A> - Parameters:
vertex- a vertex- Returns:
- the number of previous vertices
-
getPrevCount
public int getPrevCount(int v) Description copied from interface:IndexedBidiGraphReturns the number of direct predecessor vertices of v.- Specified by:
getPrevCountin interfaceIndexedBidiGraph- Parameters:
v- index of vertex v- Returns:
- the number of next vertices of v.
-
getVertex
Description copied from interface:AttributedIndexedDirectedGraphReturns the data of the specified vertex.- Specified by:
getVertexin interfaceAttributedIndexedDirectedGraph<V,A> - Specified by:
getVertexin interfaceDirectedGraph<V,A> - Parameters:
index- index of vertex- Returns:
- vertex data
-
getVertexCount
public int getVertexCount()Description copied from interface:IndexedDirectedGraphReturns the number of verticesV.- Specified by:
getVertexCountin interfaceDirectedGraph<V,A> - Specified by:
getVertexCountin interfaceIndexedDirectedGraph- Returns:
- vertex count
-
getVertexIndex
Description copied from interface:AttributedIndexedDirectedGraphReturns the index of the vertex.- Specified by:
getVertexIndexin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
vertex- a vertex- Returns:
- index of vertex
-
getVertices
Description copied from interface:BareDirectedVertexGraphReturns all vertices.- Specified by:
getVerticesin interfaceBareDirectedVertexGraph<V>- Returns:
- a set view on all vertices
-
nextVerticesEnumerator
Description copied from interface:IndexedDirectedGraphReturns the direct successor vertices of the specified vertex.- Specified by:
nextVerticesEnumeratorin interfaceIndexedDirectedGraph- Parameters:
v- a vertex index- Returns:
- a collection view on the direct successor vertices of vertex
-