Interface GraphChunk

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
Example of a bidirectional graph with a chunk-size of 2, and the following graph:
 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 Type
    Method
    Description
    int
    getArrow(int v, int k)
     
    int
    getSibling(int v, int k)
     
    int
    Gets the number of siblings of vertex v.
    int[]
    Gets the siblings array.
    int
    Gets the from-offset at which the siblings array contains indices of sibling vertices for the vertex v.
    int
     
    int
    indexOf(int v, int u)
    Gets the index of the arrow vertex v to u.
    void
    Removes all arrows from vertex v.
    int
    removeArrowAt(int v, int removalIndex)
     
    void
    setVertexData(int v, int data)
     
    boolean
    tryAddArrow(int v, int u, int data, boolean updateIfPresent)
    Tries to add an arrow from vertex v to vertex u.
    boolean
    tryRemoveArrow(int v, int u)
    Tries to remove an arrow from vertex v to vertex u.
  • Method Details

    • tryAddArrow

      boolean tryAddArrow(int v, int u, int data, boolean updateIfPresent)
      Tries to add an arrow from vertex v to vertex u.
      Parameters:
      v - the index of vertex v
      u - the index of vertex u
      data - the arrow data
      updateIfPresent - 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 vertex v to u.
      Parameters:
      v - the index of vertex v
      u - the index of vertex u
      Returns:
      the index of the arrow if present, ~insertionIndex if the arrow is absent
    • getSiblingsFromOffset

      int getSiblingsFromOffset(int v)
      Gets the from-offset at which the siblings array contains indices of sibling vertices for the vertex v.
      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 vertex v.
      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) and 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!

      Returns:
      the siblings array
    • tryRemoveArrow

      boolean tryRemoveArrow(int v, int u)
      Tries to remove an arrow from vertex v to vertex u.
      Parameters:
      v - the index of vertex v
      u - the index of vertex u
      Returns:
      true, if there was an arrow
    • removeAllArrows

      void removeAllArrows(int v)
      Removes all arrows from vertex v.
      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)