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 TypeMethodDescriptionaddNode(int node) Add the given node ordinal with an empty set of neighbors.voidclose()booleancontainsNode(int nodeId) doubledoubleintgetNodes()Get all node ordinals included in the graph.getView()Returns a view of the graph that is safe to use concurrently with updates performed on the underlying graph.voidmarkDeleted(int node) Mark the given node deleted.intlonglongvoidsave(DataOutput out) intsize()Returns the number of nodes in the graphtoString()
-
Method Details
-
size
public int size()Description copied from interface:GraphIndexReturns the number of nodes in the graph- Specified by:
sizein interfaceGraphIndex<T>
-
addNode
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:
maxDegreein interfaceGraphIndex<T>- Returns:
- the maximum number of edges per node
-
getNodes
Description copied from interface:GraphIndexGet all node ordinals included in the graph. The nodes are NOT guaranteed to be presented in any particular order.- Specified by:
getNodesin interfaceGraphIndex<T>- Returns:
- an iterator over nodes where
nextIntreturns the next node.
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceAccountable
-
ramBytesUsedOneNode
public long ramBytesUsedOneNode() -
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>
-
getDeletedNodes
-
getIdUpperBound
public int getIdUpperBound()- Specified by:
getIdUpperBoundin interfaceGraphIndex<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:
containsNodein interfaceGraphIndex<T>- Returns:
- true iff the graph contains the node with the given ordinal id
-
getAverageShortEdges
public double getAverageShortEdges() -
getAverageDegree
public double getAverageDegree() -
save
- Throws:
IOException
-