Class OnHeapGraphIndex<T>

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

public 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

    • 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 ConcurrentNeighborSet addNode(int node)
      Add the given node ordinal 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
      Returns:
      the neighbor set for this node
    • markDeleted

      public void markDeleted(int node)
      Mark the given node deleted. Does NOT remove the node from the graph.
    • 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 node ordinals included in the graph. 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 the next node.
    • ramBytesUsed

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

      public long ramBytesUsedOneNode()
    • 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>
    • getDeletedNodes

      public BitSet getDeletedNodes()
    • getIdUpperBound

      public int getIdUpperBound()
      Specified by:
      getIdUpperBound in interface GraphIndex<T>
      Returns:
      the maximum node id in the graph. May be different from size() if nodes are being added concurrently, or if nodes have been deleted (and cleaned up).
    • containsNode

      public boolean containsNode(int nodeId)
      Specified by:
      containsNode in interface GraphIndex<T>
      Returns:
      true iff the graph contains the node with the given ordinal id
    • getAverageShortEdges

      public double getAverageShortEdges()
    • getAverageDegree

      public double getAverageDegree()
    • save

      public void save(DataOutput out) throws IOException
      Throws:
      IOException