def _IndexedScan(self, i, max_records=None):
    """Scan records starting with index i."""
    if not self._index:
      self._ReadIndex()

    # The record number that we will read next.
    idx = 0
    # The timestamp that we will start reading from.
    start_ts = 0
    if i >= self._max_indexed:
      start_ts = max(
          (0, 0), (self._index[self._max_indexed][0],
                   self._index[self._max_indexed][1] - 1))
      idx = self._max_indexed
    else:
      try:
        possible_idx = i - i % self.INDEX_SPACING
        start_ts = (max(0, self._index[possible_idx][0]),
                    self._index[possible_idx][1] - 1)
        idx = possible_idx
      except __HOLE__:
        pass

    if max_records is not None:
      max_records += i - idx

    for (ts, value) in self.Scan(after_timestamp=start_ts,
                                 max_records=max_records,
                                 include_suffix=True):
      self._MaybeWriteIndex(idx, ts)
      if idx >= i:
        yield (idx, ts, value)
      idx += 1
dataset/ETHPy150Open google/grr/grr/lib/aff4_objects/sequential_collection.py/IndexedSequentialCollection._IndexedScan