class LinePartitioner implements Partitioner {

    @Override
    public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) {
        // 先排序 从低到高
        segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality()));
        int count = 0;
        List<SegmentKey> list = new ArrayList<>();
        List<SegmentPartition> partitions = new ArrayList<>();
        for (SegmentKey segmentKey : segmentKeys) {
            Segment segment = SegmentUtils.newSegment(segmentKey);
            count += segment.getAllShowIndex().getCardinality();
            if (count >= capacity) {
                partitions.add(new SegmentPartition(list));
                list = new ArrayList<>();
                list.add(segmentKey);
                count = segment.getAllShowIndex().getCardinality();
            } else {
                list.add(segmentKey);
            }
        }
        if (!list.isEmpty()) {
            partitions.add(new SegmentPartition(list));
        }
        Iterator<SegmentPartition> iterator = partitions.iterator();
        while (iterator.hasNext()) {
            SegmentPartition next = iterator.next();
            //seg.size == 1且capacity>=4/5的进不来
            //2<=seg.size<=4时capacity才可能>=4/5
            if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) {
                iterator.remove();
            }
        }
        return partitions;
    }

    public  LinePartitioner(int capacity);

}