public int compact(RangeIndex newRangeIndex, Set<Long> compactedObjectIds) {
        if (compactedObjectIds.isEmpty()) {
            return append(newRangeIndex);
        }
        List<RangeIndex> newRangeIndexList = new ArrayList<>();
        boolean found = false;
        for (RangeIndex rangeIndex : this.sortedRangeIndexList) {
            if (compactedObjectIds.contains(rangeIndex.getObjectId())) {
                continue;
            }
            if (newRangeIndex != null && !found && rangeIndex.compareTo(newRangeIndex) > 0) {
                // insert new range index into the list
                newRangeIndexList.add(newRangeIndex);
                found = true;
            }
            newRangeIndexList.add(rangeIndex);
        }
        if (newRangeIndex != null && !found) {
            // insert new range index into the end of the list
            newRangeIndexList.add(newRangeIndex);
        }
        int oldSize = size;
        init(newRangeIndexList);
        return size - oldSize;
    }
Compact the list by removing the compacted object ids and add the new range index if not null.

@param newRangeIndex the new range index to add
@param compactedObjectIds the object ids to compact
@return the change of size after compacting
s3stream/src/main/java/com/automq/stream/s3/index/SparseRangeIndex.java