Package org.apache.lucene.util.hnsw
Class NeighborArray
java.lang.Object
org.apache.lucene.util.hnsw.NeighborArray
NeighborArray encodes the neighbors of a node and their mutual scores in the HNSW graph as a pair
of growable arrays. Nodes are arranged in the sorted order of their scores in descending order
(if scoresDescOrder is true), or in the ascending order of their scores (if scoresDescOrder is
false)
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInOrder
(int newNode, float newScore) Add a new node to the NeighborArray.void
addOutOfOrder
(int newNode, float newScore) Add node and newScore but do not insert as sortedvoid
clear()
int[]
node()
Direct access to the internal list of node ids; provided for efficient writing of the graphvoid
removeIndex
(int idx) void
float[]
score()
int
size()
int[]
sort
(RandomVectorScorer scorer) Sort the array according to scores, and return the sorted indexes of previous unsorted nodes (unchecked nodes)toString()
-
Field Details
-
rwlock
-
-
Constructor Details
-
NeighborArray
public NeighborArray(int maxSize, boolean descOrder)
-
-
Method Details
-
addInOrder
public void addInOrder(int newNode, float newScore) Add a new node to the NeighborArray. The new node must be worse than all previously stored nodes. This cannot be called afteraddOutOfOrder(int, float)
-
addOutOfOrder
public void addOutOfOrder(int newNode, float newScore) Add node and newScore but do not insert as sorted -
sort
Sort the array according to scores, and return the sorted indexes of previous unsorted nodes (unchecked nodes)- Returns:
- indexes of newly sorted (unchecked) nodes, in ascending order, or null if the array is already fully sorted
- Throws:
IOException
-
size
public int size() -
node
public int[] node()Direct access to the internal list of node ids; provided for efficient writing of the graph- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
score
public float[] score() -
clear
public void clear() -
removeLast
public void removeLast() -
removeIndex
public void removeIndex(int idx) -
toString
-