code: private KNNHeap linearScan(Relation<? extends O> relation, DBIDIter iter, final O obj, KNNHeap heap) {
      final SquaredEuclideanDistanceFunction squared = SquaredEuclideanDistanceFunction.STATIC;
      double max = Double.POSITIVE_INFINITY;
      while(iter.valid()) {
        final double dist = squared.distance(obj, relation.get(iter));
        if(dist <= max) {
          max = heap.insert(dist, iter);
        }
        iter.advance();
      }
      return heap;
    }
docs: Main loop of the linear scan.
  
  @param relation Data relation
  @param iter ID iterator
  @param obj Query object
  @param heap Output heap
  @return Heap