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)
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int[]
(package private) float[]
private final boolean
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int newNode, float newScore) Add a new node to the NeighborArray.private int
ascSortFindRightMostInsertionPoint
(float newScore) void
clear()
private int
descSortFindRightMostInsertionPoint
(float newScore) void
insertSorted
(int newNode, float newScore) Add a new node to the NeighborArray 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 graphvoid
removeIndex
(int idx) void
float[]
score()
int
size()
toString()
-
Field Details
-
scoresDescOrder
private final boolean scoresDescOrder -
size
private int size -
score
float[] score -
node
int[] node
-
-
Constructor Details
-
NeighborArray
public NeighborArray(int maxSize, boolean descOrder)
-
-
Method Details
-
add
public void add(int newNode, float newScore) Add a new node to the NeighborArray. The new node must be worse than all previously stored nodes. -
insertSorted
public void insertSorted(int newNode, float newScore) Add a new node to the NeighborArray into a correct sort position according to its score. -
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
-
ascSortFindRightMostInsertionPoint
private int ascSortFindRightMostInsertionPoint(float newScore) -
descSortFindRightMostInsertionPoint
private int descSortFindRightMostInsertionPoint(float newScore)
-