Package io.github.jbellis.jvector.graph
Class NodeArray
java.lang.Object
io.github.jbellis.jvector.graph.NodeArray
NodeArray encodes nodeids and their scores relative to some other element
(a query vector, or another graph node) as a pair of growable arrays.
Nodes are arranged in the sorted order of their scores in descending order,
i.e. the most-similar nodes are first.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInOrder(int newNode, float newScore) Add a new node to the NodeArray.voidclear()copy()protected final intdescSortFindRightMostInsertionPoint(float newScore) protected final voidbooleaninsertSorted(int newNode, float newScore) Add a new node to the NodeArray into a correct sort position according to its score.int[]node()Direct access to the internal list of node ids; provided for efficient writing of the graphvoidremoveIndex(int idx) voidvoidRetains only the elements in the current NodeArray whose corresponding index is set in the given BitSet.float[]score()intsize()toString()
-
Field Details
-
EMPTY
-
size
protected int size
-
-
Constructor Details
-
NodeArray
public NodeArray(int maxSize)
-
-
Method Details
-
addInOrder
public void addInOrder(int newNode, float newScore) Add a new node to the NodeArray. The new node must be worse than all previously stored nodes. -
insertSorted
public boolean insertSorted(int newNode, float newScore) Add a new node to the NodeArray into a correct sort position according to its score. Duplicate node + score pairs are ignored.- Returns:
- true if the new node + score pair did not already exist
-
retain
Retains only the elements in the current NodeArray whose corresponding index is set in the given BitSet.This modifies the array in place, preserving the relative order of the elements retained.
- Parameters:
selected- A BitSet where the bit at index i is set if the i-th element should be retained. (Thus, the elements of selected represent positions in the NodeArray, NOT node ids.)
-
copy
-
growArrays
protected final void growArrays() -
size
public int size() -
node
public int[] node()Direct access to the internal list of node ids; provided for efficient writing of the graph -
score
public float[] score() -
clear
public void clear() -
removeLast
public void removeLast() -
removeIndex
public void removeIndex(int idx) -
toString
-
descSortFindRightMostInsertionPoint
protected final int descSortFindRightMostInsertionPoint(float newScore)
-