final KNNHeap<DoubleDistance> heap = new KNNHeap<DoubleDistance>(k);
double max = Double.POSITIVE_INFINITY;
for(DBID candidateID : relation.iterDBIDs()) {
final double doubleDistance = rawdist.doubleDistance(obj, relation.get(candidateID));
if(doubleDistance <= max) {
heap.add(new DoubleDistanceResultPair(doubleDistance, candidateID));
// Update cutoff
if(heap.size() >= heap.getK()) {
max = ((DoubleDistanceResultPair) heap.peek()).getDoubleDistance();
}
}