Class ConcurrentNeighborSet

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

public class ConcurrentNeighborSet extends Object
A concurrent set of neighbors that encapsulates diversity/pruning mechanics.
  • Constructor Details

    • ConcurrentNeighborSet

      public ConcurrentNeighborSet(int nodeId, int maxConnections, NodeSimilarity similarity)
    • ConcurrentNeighborSet

      public ConcurrentNeighborSet(int nodeId, int maxConnections, NodeSimilarity similarity, float alpha)
  • Method Details

    • getShortEdges

      public float getShortEdges()
    • iterator

      public NodesIterator iterator()
    • backlink

      public void backlink(Function<Integer,ConcurrentNeighborSet> neighborhoodOf, float overflow)
      For every neighbor X that this node Y connects to, add a reciprocal link from X to Y. If overflow is > 1.0, allow the number of neighbors to exceed maxConnections temporarily.
    • cleanup

      public void cleanup()
      Enforce maxConnections as a hard cap, since we allow it to be exceeded temporarily during construction for efficiency. This method is threadsafe, but if you call it concurrently with other inserts, the limit may end up being exceeded again.
    • removeDeletedNeighbors

      public boolean removeDeletedNeighbors(Bits deletedNodes)
      Returns:
      true if we had deleted neighbors
    • size

      public int size()
    • arrayLength

      public int arrayLength()
    • insertDiverse

      public void insertDiverse(NodeArray natural, NodeArray concurrent)
      For each candidate (going from best to worst), select it only if it is closer to target than it is to any of the already-selected candidates. This is maintained whether those other neighbors were selected by this method, or were added as a "backlink" to a node inserted concurrently that chose this one as a neighbor.
    • insert

      public void insert(int neighborId, float score, float overflow)
      Insert a new neighbor, maintaining our size cap by removing the least diverse neighbor if necessary. "Overflow" is the factor by which to allow going over the size cap temporarily.
    • copy

      public ConcurrentNeighborSet copy()