Class NodeArray

java.lang.Object
io.github.jbellis.jvector.graph.NodeArray

public class NodeArray extends Object
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 Details

    • EMPTY

      public static final NodeArray 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

      public void retain(Bits selected)
      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

      public NodeArray 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

      public String toString()
      Overrides:
      toString in class Object
    • descSortFindRightMostInsertionPoint

      protected final int descSortFindRightMostInsertionPoint(float newScore)