code: private Segment compactGroup(List<Segment> segments, List<OffsetPredicate> predicates) {
      // Get the first segment which contains the first index being compacted. The compact segment will be written
      // as a newer version of the earliest segment being rewritten.
      Segment firstSegment = segments.iterator().next();
  
      // Create a compacted segment with a newer version to which to rewrite the segment entries.
      Segment compactSegment = manager.createSegment(SegmentDescriptor.builder()
        .withId(firstSegment.descriptor().id())
        .withVersion(firstSegment.descriptor().version() + 1)
        .withIndex(firstSegment.descriptor().index())
        .withMaxSegmentSize(Math.max(segments.stream().mapToLong(s -> s.descriptor().maxSegmentSize()).max().getAsLong(), manager.storage().maxSegmentSize()))
        .withMaxEntries(Math.max(segments.stream().mapToInt(s -> s.descriptor().maxEntries()).max().getAsInt(), manager.storage().maxEntriesPerSegment()))
        .build());
  
      compactGroup(segments, predicates, compactSegment);
  
      // Replace the rewritten segments with the updated segment.
      manager.replaceSegments(segments, compactSegment);
  
      return compactSegment;
    }
docs: Compacts a group.