java.lang.Object
org.jhotdraw8.graph.SingleArrayCsrGraphChunk
- All Implemented Interfaces:
GraphChunk
Stores a chunk of a graph using a "Compressed Sparse Row" representation.
Uses one shared gap between the list of sibling vertices/arrows. Moves the gap at each insertion/deletion operation. This may make it slow for updates.
The vertex data, the siblings list and arrows list are stored in a single array.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetArrow(int v, int k) intgetSibling(int v, int k) intgetSiblingCount(int v) Gets the number of siblings of vertexv.int[]Gets the siblings array.intgetSiblingsFromOffset(int v) Gets thefrom-offset at which the siblings array contains indices of sibling vertices for the vertexv.intgetVertexData(int v) intindexOf(int v, int u) Finds the index of vertex u in the sibling list of vertex v.voidremoveAllArrows(int v) Removes all arrows starting at vertex v.intremoveArrowAt(int v, int removalIndex) Removes an arrow from vertex v to the a vertex u at the specified index.voidsetVertexData(int v, int data) booleantryAddArrow(int v, int u, int data, boolean updateIfPresent) Adds an arrow from vertex v to vertex u with the provided arrow data.booleantryRemoveArrow(int v, int u) Removes an arrow from vertex v to vertex u, if it is present.
-
Constructor Details
-
SingleArrayCsrGraphChunk
public SingleArrayCsrGraphChunk(int vertexCount, int initialArrowCapacity)
-
-
Method Details
-
indexOf
public int indexOf(int v, int u) Finds the index of vertex u in the sibling list of vertex v.- Specified by:
indexOfin interfaceGraphChunk- Parameters:
v- index of vertex vu- index of vertex u- Returns:
- the index of u or (-index -1) if u is not in the index list.
-
getSiblingsArray
public int[] getSiblingsArray()Description copied from interface:GraphChunkGets the siblings array. This is a single array for all siblings.Use
GraphChunk.getSiblingsFromOffset(int)andGraphChunk.getSiblingCount(int)to access the siblings of a specific vertex.The content of this array and the offsets changes when arrows are added or removed!
- Specified by:
getSiblingsArrayin interfaceGraphChunk- Returns:
- the siblings array
-
getSiblingCount
public int getSiblingCount(int v) Description copied from interface:GraphChunkGets the number of siblings of vertexv.- Specified by:
getSiblingCountin interfaceGraphChunk- Parameters:
v- the index of vertex v- Returns:
- the number of siblings
-
getVertexData
public int getVertexData(int v) - Specified by:
getVertexDatain interfaceGraphChunk
-
setVertexData
public void setVertexData(int v, int data) - Specified by:
setVertexDatain interfaceGraphChunk
-
getArrow
public int getArrow(int v, int k) - Specified by:
getArrowin interfaceGraphChunk
-
getSiblingsFromOffset
public int getSiblingsFromOffset(int v) Description copied from interface:GraphChunkGets thefrom-offset at which the siblings array contains indices of sibling vertices for the vertexv.- Specified by:
getSiblingsFromOffsetin interfaceGraphChunk- Parameters:
v- the index of vertex v- Returns:
- the
from-offset in the siblings array - See Also:
-
getSibling
public int getSibling(int v, int k) - Specified by:
getSiblingin interfaceGraphChunk
-
tryAddArrow
public boolean tryAddArrow(int v, int u, int data, boolean updateIfPresent) Adds an arrow from vertex v to vertex u with the provided arrow data. Optionally updates the arrow data if the arrow is present.- Specified by:
tryAddArrowin interfaceGraphChunk- Parameters:
v- index of vertex vu- index of vertex udata- the arrow dataupdateIfPresent- sets the data if the arrow is present- Returns:
- true if a new arrow was added
-
tryRemoveArrow
public boolean tryRemoveArrow(int v, int u) Removes an arrow from vertex v to vertex u, if it is present.- Specified by:
tryRemoveArrowin interfaceGraphChunk- Parameters:
v- index of vertex vu- index of vertex u- Returns:
- true on success
-
removeAllArrows
public void removeAllArrows(int v) Removes all arrows starting at vertex v.- Specified by:
removeAllArrowsin interfaceGraphChunk- Parameters:
v- index of vertex v
-
removeArrowAt
public int removeArrowAt(int v, int removalIndex) Removes an arrow from vertex v to the a vertex u at the specified index.- Specified by:
removeArrowAtin interfaceGraphChunk- Parameters:
v- index of vertex vremovalIndex- index of vertex u- Returns:
- returns the removed arrow u
-