java.lang.Object
org.elasticsearch.index.codec.vectors.cluster.NeighborQueue

public class NeighborQueue extends Object
Copied from and modified from Apache Lucene.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NeighborQueue(int initialSize, boolean maxHeap)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int newNode, float newScore)
    Adds a new graph arc, extending the storage as needed.
    void
     
    float
    decodeScore(long heapValue)
     
    static float
    decodeScoreRaw(long heapValue)
     
    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.
    static long
    encodeRaw(int node, float score)
     
    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.
    boolean
    insertWithOverflow(long encoded)
     
    long
     
    int
    pop()
    Removes the top element and returns its node id.
    int
     
    int
    Returns the top element's node id.
    float
    Returns the top element's node score.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 id
      newScore - 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 id
      newScore - 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 ID
      score - 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.
    • clear

      public void clear()
    • toString

      public String toString()
      Overrides:
      toString in class Object