Package io.github.jbellis.jvector.graph
Class NeighborQueue
java.lang.Object
io.github.jbellis.jvector.graph.NeighborQueue
NeighborQueue uses a
LongHeap to store lists of arcs in a graph, represented as a
neighbor node id with an associated score packed together as a sortable long, which is sorted
primarily by score. The queue provides both fixed-size and unbounded operations via insertWithReplacement(int, float) and add(int, float), and provides MIN and MAX heap
subclasses.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int newNode, float newScore) Adds a new graph arc, extending the storage as needed.voidclear()booleanbooleaninsertWithReplacement(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.voidint[]Returns a copy of the internal nodes array.intpop()Removes the top element and returns its node id.intsize()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
-
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
-
insertWithReplacement
public boolean insertWithReplacement(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 newScore against the current worst score; if newScore is better, the worst node+score is discarded and newNode+newScore is added.- Parameters:
newNode- the neighbor node idnewScore- the score of the neighbor, relative to some other node
-
pop
public int pop()Removes the top element and returns its node id. -
nodesCopy
public int[] nodesCopy()Returns a copy of the internal nodes array. Not sorted by score! -
nodesCopy
-
topNode
public int topNode()Returns the top element's node id. -
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. -
clear
public void clear() -
incomplete
public boolean incomplete() -
markIncomplete
public void markIncomplete() -
toString
-