Class ImmutableAttributed16BitIndexedDirectedGraph<V,A>
- Type Parameters:
V- the vertex data typeA- the arrow data type
- All Implemented Interfaces:
AttributedIndexedDirectedGraph<V,,A> BareDirectedGraph<V,,A> BareDirectedVertexGraph<V>,DirectedGraph<V,,A> IndexedDirectedGraph
Supports up to 2^16 - 1 vertices.
Uses a representation that is similar to a compressed row storage for
matrices (CRS). A directed graph is represented with 4 arrays:
nextOffset, next, nextArrows, 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. vertices- Holds for each vertex
vthe data associated to the vertex.
- Author:
- Werner Randelshofer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final short @NonNull []Holds the indices to the next vertices.Holds the arrow objects.protected final short @NonNull []Holds offsets into thenexttable and thenextArrowstable.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.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.AttributedIndexedDirectedGraph
getNextIntEntriesMethods inherited from interface org.jhotdraw8.graph.DirectedGraph
findArrow, findIndexOfNext, getArrows, getArrows, getNextArc, getNextArcs, getNextArrows, getNextVertices, isNext, searchNextVertices, searchNextVerticesMethods 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 -
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. -
nextArrows
Holds the arrow objects.The arrows are stored in consecutive runs for each vertex, starting at the offset given by
nextOffset.See
next. -
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
-
ImmutableAttributed16BitIndexedDirectedGraph
public ImmutableAttributed16BitIndexedDirectedGraph(@NonNull AttributedIndexedDirectedGraph<V, A> graph) Creates a new instance from the specified graph.- Parameters:
graph- a graph
-
ImmutableAttributed16BitIndexedDirectedGraph
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
-
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
-