- All Known Implementing Classes:
MultiArrayCsrGraphChunk,SingleArrayCsrGraphChunk
public interface GraphChunk
Interface for a chunk of a
ChunkedMutableIndexedBidiGraph.
A chunk contains a sub-set of the vertices and arrows of a graph.
The sub-set contains a power-of-two of vertices. Multi-graphs are not supported.
A chunk only contains arrows in one direction. For a bidirectional graph, we need one chunk for arrows in the 'next' direction, and one chunk for the arrows in 'prev' direction.
Since a chunk also contains vertex data and arrow data, the data must be stored twice, once in the 'next' direction, and once in the 'prev' direction.
A chunk stores the following data:
- vertex data
- one 32-bit int data element for each vertex
- siblings
- one 32-bit int index for each sibling
- arrow data
- one 32-bit int data element for each arrow to a sibling
The vertices have indices 0 through 4 and the same data.
The arrows have negative values.
-1 -12
0 ─→ 1 ─→ 2
│ │
-14 ↓ ↓ -23
4 ←─ 3
-34
nextChunks[0] = vertices: 0, 1
siblings: 0→1, 1→2, 1→4,
arrows: -1, -12, -14
nextChunks[1] = vertices: 2, 3
siblings: 2→3, 3→4
arrows: -23, -34
nextChunks[2] = vertices: 4, ∅
siblings:
arrows:
prevChunks[0] = vertices: 0, 1
siblings: 1←0
arrows: -1
prevChunks[1] = vertices: 2, 3
siblings: 2←1, 3←2
arrows: -12, -23
prevChunks[2] = vertices: 4, ∅
siblings: 4←1, 4←3
arrows: -13 -34
-
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) Gets the index of the arrow vertexvtou.voidremoveAllArrows(int v) Removes all arrows from vertexv.intremoveArrowAt(int v, int removalIndex) voidsetVertexData(int v, int data) booleantryAddArrow(int v, int u, int data, boolean updateIfPresent) Tries to add an arrow from vertexvto vertexu.booleantryRemoveArrow(int v, int u) Tries to remove an arrow from vertexvto vertexu.
-
Method Details
-
tryAddArrow
boolean tryAddArrow(int v, int u, int data, boolean updateIfPresent) Tries to add an arrow from vertexvto vertexu.- Parameters:
v- the index of vertex vu- the index of vertex udata- the arrow dataupdateIfPresent- when true, updates the arrow data if the arrow is already present- Returns:
- true, if the arrow is already present
-
indexOf
int indexOf(int v, int u) Gets the index of the arrow vertexvtou.- Parameters:
v- the index of vertex vu- the index of vertex u- Returns:
- the index of the arrow if present,
~insertionIndexif the arrow is absent
-
getSiblingsFromOffset
int getSiblingsFromOffset(int v) Gets thefrom-offset at which the siblings array contains indices of sibling vertices for the vertexv.- Parameters:
v- the index of vertex v- Returns:
- the
from-offset in the siblings array - See Also:
-
getSiblingCount
int getSiblingCount(int v) Gets the number of siblings of vertexv.- Parameters:
v- the index of vertex v- Returns:
- the number of siblings
-
getSiblingsArray
int[] getSiblingsArray()Gets the siblings array. This is a single array for all siblings.Use
getSiblingsFromOffset(int)andgetSiblingCount(int)to access the siblings of a specific vertex.The content of this array and the offsets changes when arrows are added or removed!
- Returns:
- the siblings array
-
tryRemoveArrow
boolean tryRemoveArrow(int v, int u) Tries to remove an arrow from vertexvto vertexu.- Parameters:
v- the index of vertex vu- the index of vertex u- Returns:
- true, if there was an arrow
-
removeAllArrows
void removeAllArrows(int v) Removes all arrows from vertexv.- Parameters:
v- the index of vertex v
-
removeArrowAt
int removeArrowAt(int v, int removalIndex) -
getSibling
int getSibling(int v, int k) -
getArrow
int getArrow(int v, int k) -
getVertexData
int getVertexData(int v) -
setVertexData
void setVertexData(int v, int data)
-