Class OnHeapGraphIndex<T>

java.lang.Object
io.github.jbellis.jvector.graph.OnHeapGraphIndex<T>
All Implemented Interfaces:
GraphIndex<T>, Accountable, AutoCloseable

public final class OnHeapGraphIndex<T> extends Object implements GraphIndex<T>, Accountable
An GraphIndex that offers concurrent access; for typical graphs you will get significant speedups in construction and searching as you add threads.

To search this graph, you should use a View obtained from getView() to perform `seek` and `nextNeighbor` operations.

  • Method Details

    • getNeighbors

      public ConcurrentNeighborSet getNeighbors(int node)
      Returns the neighbors connected to the given node.
      Parameters:
      node - the node whose neighbors are returned, represented as an ordinal on the level 0.
    • size

      public int size()
      Description copied from interface: GraphIndex
      Returns the number of nodes in the graph
      Specified by:
      size in interface GraphIndex<T>
    • addNode

      public void addNode(int node)
      Add node on the given level with an empty set of neighbors.

      Nodes can be inserted out of order, but it requires that the nodes preceded by the node inserted out of order are eventually added.

      Actually populating the neighbors, and establishing bidirectional links, is the responsibility of the caller.

      It is also the responsibility of the caller to ensure that each node is only added once.

      Parameters:
      node - the node to add, represented as an ordinal on the level 0.
    • updateEntryNode

      public void updateEntryNode(int node)
    • maxDegree

      public int maxDegree()
      Specified by:
      maxDegree in interface GraphIndex<T>
      Returns:
      the maximum number of edges per node
    • getNodes

      public NodesIterator getNodes()
      Description copied from interface: GraphIndex
      Get all nodes on a given level as node 0th ordinals. The nodes are NOT guaranteed to be presented in any particular order.
      Specified by:
      getNodes in interface GraphIndex<T>
      Returns:
      an iterator over nodes where nextInt returns a next node on the level
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface Accountable
    • ramBytesUsedOneNode

      public long ramBytesUsedOneNode(int nodeLevel)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface GraphIndex<T>
    • getView

      public GraphIndex.View<T> getView()
      Returns a view of the graph that is safe to use concurrently with updates performed on the underlying graph.

      Multiple Views may be searched concurrently.

      Specified by:
      getView in interface GraphIndex<T>