*/
protected void doKNNQuery(O object, KNNHeap<DoubleDistance> knnList) {
final Heap<DoubleDistanceSearchCandidate> pq = new UpdatableHeap<DoubleDistanceSearchCandidate>();
// push root
pq.add(new DoubleDistanceSearchCandidate(0.0, tree.getRootID()));
double maxDist = Double.MAX_VALUE;
// search in tree
while(!pq.isEmpty()) {
DoubleDistanceSearchCandidate pqNode = pq.poll();
if(pqNode.mindist > maxDist) {
return;
}
AbstractRStarTreeNode<?, ?> node = tree.getNode(pqNode.nodeID);
// data node
if(node.isLeaf()) {
for(int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry entry = node.getEntry(i);
double distance = distanceFunction.doubleMinDist(entry, object);
tree.distanceCalcs++;
if(distance <= maxDist) {
knnList.add(new DoubleDistanceResultPair(distance, ((LeafEntry) entry).getDBID()));
maxDist = knnList.getKNNDistance().doubleValue();
}
}
}
// directory node
else {
for(int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry entry = node.getEntry(i);
double distance = distanceFunction.doubleMinDist(entry, object);
tree.distanceCalcs++;
if(distance <= maxDist) {
pq.add(new DoubleDistanceSearchCandidate(distance, ((DirectoryEntry)entry).getPageID()));
}
}
}
}
}