private void reinitializeCellSet(int numOfCells, KeyValueScanner segmentScanner,
    CellSet<ExtendedCell> oldCellSet, MemStoreCompactionStrategy.Action action) {
    ExtendedCell[] cells = new ExtendedCell[numOfCells]; // build the Cell Array
    ExtendedCell curCell;
    int idx = 0;
    int numUniqueKeys = 0;
    ExtendedCell prev = null;
    try {
      while ((curCell = segmentScanner.next()) != null) {
        cells[idx++] = curCell;
        if (action == MemStoreCompactionStrategy.Action.FLATTEN_COUNT_UNIQUE_KEYS) {
          // counting number of unique keys
          if (prev != null) {
            if (!CellUtil.matchingRowColumn(prev, curCell)) {
              numUniqueKeys++;
            }
          } else {
            numUniqueKeys++;
          }
        }
        prev = curCell;
      }
    } catch (IOException ie) {
      throw new IllegalStateException(ie);
    } finally {
      segmentScanner.close();
    }
    if (action != MemStoreCompactionStrategy.Action.FLATTEN_COUNT_UNIQUE_KEYS) {
      numUniqueKeys = CellSet.UNKNOWN_NUM_UNIQUES;
    }
    // build the immutable CellSet
    CellArrayMap<ExtendedCell> cam = new CellArrayMap<>(getComparator(), cells, 0, idx, false);
    // update the CellSet of this Segment
    this.setCellSet(oldCellSet, new CellSet<>(cam, numUniqueKeys));
  }
------------------------------------------------------------------------ C-tor to be used when
new CellChunkImmutableSegment is built as a result of flattening of CSLMImmutableSegment The
given iterator returns the Cells that "survived" the compaction.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellArrayImmutableSegment.java