Module org.elasticsearch.server
Class NeighborQueue
java.lang.Object
org.elasticsearch.index.codec.vectors.cluster.NeighborQueue
Copied from and modified from Apache Lucene.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int newNode, float newScore) Adds a new graph arc, extending the storage as needed.voidclear()floatdecodeScore(long heapValue) static floatdecodeScoreRaw(long heapValue) longencode(int node, float score) Encodes the node ID and its similarity score as long, preserving the Lucene tie-breaking rule that when two scores are equal, the smaller node ID must win.static longencodeRaw(int node, float score) booleaninsertWithOverflow(int newNode, float newScore) If the heap is not full (size is less than the initialSize provided to the constructor), adds a new node-and-score element.booleaninsertWithOverflow(long encoded) longpeek()intpop()Removes the top element and returns its node id.intpopAndAddRaw(long raw) if the new element is the new top then return its node id.longpopRaw()Removes the top element and returns itintsize()inttopNode()Returns the top element's node id.floattopScore()Returns the top element's node score.toString()
-
Constructor Details
-
NeighborQueue
public NeighborQueue(int initialSize, boolean maxHeap)
-
-
Method Details
-
size
public int size()- Returns:
- the number of elements in the heap
-
peek
public long peek() -
add
public void add(int newNode, float newScore) Adds a new graph arc, extending the storage as needed.- Parameters:
newNode- the neighbor node idnewScore- the score of the neighbor, relative to some other node
-
insertWithOverflow
public boolean insertWithOverflow(int newNode, float newScore) If the heap is not full (size is less than the initialSize provided to the constructor), adds a new node-and-score element. If the heap is full, compares the score against the current top score, and replaces the top element if newScore is better than (greater than unless the heap is reversed), the current top score.- Parameters:
newNode- the neighbor node idnewScore- the score of the neighbor, relative to some other node
-
insertWithOverflow
public boolean insertWithOverflow(long encoded) -
encode
public long encode(int node, float score) Encodes the node ID and its similarity score as long, preserving the Lucene tie-breaking rule that when two scores are equal, the smaller node ID must win.- Parameters:
node- the node IDscore- the node score- Returns:
- the encoded score, node ID
-
topNode
public int topNode()Returns the top element's node id. -
encodeRaw
public static long encodeRaw(int node, float score) -
decodeScoreRaw
public static float decodeScoreRaw(long heapValue) -
topScore
public float topScore()Returns the top element's node score. For the min heap this is the minimum score. For the max heap this is the maximum score. -
decodeScore
public float decodeScore(long heapValue) -
pop
public int pop()Removes the top element and returns its node id. -
popRaw
public long popRaw()Removes the top element and returns it -
popAndAddRaw
public int popAndAddRaw(long raw) if the new element is the new top then return its node id. Otherwise, removes the current top element, returns its node id and adds the new element to the queue. -
clear
public void clear() -
toString
-