Last active
July 15, 2021 00:13
-
-
Save justhackit/6e2bcb9abe14759333515fa2e2dcd81a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeMergeBatches(fileSizesMap: scala.collection.immutable.Map[String, Long], maxTargetFileSize: Long): ListBuffer[ListBuffer[String]] = { | |
val sortedFileSizes = fileSizesMap.toSeq.sortBy(_._2) | |
val groupedFiles = ListBuffer[ListBuffer[String]]() | |
groupedFiles += ListBuffer[String]() | |
for (aFile <- smallerFiles) { | |
val lastBatch = groupedFiles.last | |
if ((sizeOfThisBatch(lastBatch) + aFile._2) < maxTargetFileSize) { | |
lastBatch += aFile._1 + "|" + aFile._2.toString | |
} else { | |
val newBatch = ListBuffer[String]() | |
newBatch += aFile._1 + "|" + aFile._2.toString | |
groupedFiles += newBatch | |
} | |
} | |
groupedFiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment