Package io.github.jbellis.jvector.graph
Class OnHeapGraphIndex<T>
java.lang.Object
io.github.jbellis.jvector.graph.OnHeapGraphIndex<T>
- All Implemented Interfaces:
GraphIndex<T>,Accountable,AutoCloseable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.jbellis.jvector.graph.GraphIndex
GraphIndex.View<T> -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNode(int node) Add node on the given level with an empty set of neighbors.voidclose()getNeighbors(int node) Returns the neighbors connected to the given node.getNodes()Get all nodes on a given level as node 0th ordinals.getView()Returns a view of the graph that is safe to use concurrently with updates performed on the underlying graph.intlonglongramBytesUsedOneNode(int nodeLevel) intsize()Returns the number of nodes in the graphtoString()voidupdateEntryNode(int node)
-
Method Details
-
getNeighbors
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:GraphIndexReturns the number of nodes in the graph- Specified by:
sizein interfaceGraphIndex<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:
maxDegreein interfaceGraphIndex<T>- Returns:
- the maximum number of edges per node
-
getNodes
Description copied from interface:GraphIndexGet all nodes on a given level as node 0th ordinals. The nodes are NOT guaranteed to be presented in any particular order.- Specified by:
getNodesin interfaceGraphIndex<T>- Returns:
- an iterator over nodes where
nextIntreturns a next node on the level
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceAccountable
-
ramBytesUsedOneNode
public long ramBytesUsedOneNode(int nodeLevel) -
toString
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGraphIndex<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:
getViewin interfaceGraphIndex<T>
-