docs: @Override
    public long scanAndAggregate(
        DimensionSelector dimensionSelector,
        BufferAggregator aggregator,
        int aggregatorSize,
        Cursor cursor,
        int[] positions,
        ByteBuffer resultsBuffer
    )
    {
      long processedRows = 0;
      int positionToAllocate = 0;
      while (!cursor.isDoneOrInterrupted()) {
        final IndexedInts dimValues = dimensionSelector.getRow();
        final int dimSize = dimValues.size();
        for (int i = 0; i < dimSize; i++) {
          int dimIndex = dimValues.get(i);
          int position = positions[dimIndex];
          if (position >= 0) {
            aggregator.aggregate(resultsBuffer, position);
          } else if (position == TopNAlgorithm.INIT_POSITION_VALUE) {
            positions[dimIndex] = positionToAllocate;
            position = positionToAllocate;
            aggregator.init(resultsBuffer, position);
            aggregator.aggregate(resultsBuffer, position);
            positionToAllocate += aggregatorSize;
          }
        }
        processedRows++;
        cursor.advanceUninterruptibly();
      }
      return processedRows;
    }