ReducedGaussianGrid extends AbstractGaussianGrid { @Override public int getRowIndex(long binIndex) { if (binIndex == lastBinIndex) { return lastRow; } int minRow = 0; int maxRow = getNumRows() - 1; while (true) { int midRow = (minRow + maxRow) / 2; long lowBinIndex = getFirstBinIndex(midRow); long highBinIndex = lowBinIndex + (getNumCols(midRow) - 1); if (binIndex < lowBinIndex) { maxRow = midRow - 1; } else if (binIndex >= lowBinIndex && binIndex <= highBinIndex) { lastBinIndex = binIndex; lastRow = midRow; return midRow; } else if (binIndex > highBinIndex) { minRow = midRow + 1; } } } ReducedGaussianGrid(int numRows); @Override int getRowIndex(long binIndex); @Override long getNumBins();  }
@Test public void testRowIndex() { assertEquals(1, grid.getRowIndex(20)); assertEquals(6, grid.getRowIndex(270)); }