private void partitionIndexSegments(Map<Offset, IndexSegment> toRemove, Set<Offset> toRetain) {
    int i = 0;
    for (Map.Entry<Offset, IndexSegment> indexSegmentEntry : state.index.getIndexSegments().entrySet()) {
      if (indexSegmentEntry.getValue().getEndOffset().compareTo(state.index.journal.getFirstOffset()) >= 0
          || i % 3 != 0) {
        toRetain.add(indexSegmentEntry.getKey());
      } else {
        toRemove.put(indexSegmentEntry.getKey(), indexSegmentEntry.getValue());
      }
      i++;
    }
  }
Partitions all the available index segments in {@link CuratedLogIndexState#index} into ones that will be removed
and ones that will be retained.
@param toRemove a {@link Map} that will contain all the {@link Offset} and {@link IndexSegment} instances that need
                to be removed.
@param toRetain a {@link Set} that will contain all the {@link Offset} of {@link IndexSegment} instances that need
                to be retained.
ambry-store/src/test/java/com/github/ambry/store/IndexTest.java