code: public List<List<Segment>> getCompactableGroups(Storage storage, SegmentManager manager) {
      List<List<Segment>> compact = new ArrayList<>();
      List<Segment> segments = null;
      for (Segment segment : getCompactableSegments(manager)) {
        // If this is the first segment in a segments list, add the segment.
        if (segments == null) {
          segments = new ArrayList<>();
          segments.add(segment);
        }
        // If the total size of all segments is less than the maximum size of any segment, add the segment to the segments list.
        else if (segments.stream().mapToLong(Segment::size).sum() + segment.size() <= storage.maxSegmentSize()
          && segments.stream().mapToLong(Segment::count).sum() + segment.count() <= storage.maxEntriesPerSegment()) {
          segments.add(segment);
        }
        // If there's not enough room to combine segments, reset the segments list.
        else {
          compact.add(segments);
          segments = new ArrayList<>();
          segments.add(segment);
        }
      }
  
      // Ensure all compactable segments have been added to the compact segments list.
      if (segments != null) {
        compact.add(segments);
      }
      return compact;
    }
docs: Returns a list of segments lists to compact, where segments are grouped according to how they will be merged during
  compaction.