Skip to content

Instantly share code, notes, and snippets.

@justhackit
Last active July 15, 2021 00:13
Show Gist options
  • Save justhackit/6e2bcb9abe14759333515fa2e2dcd81a to your computer and use it in GitHub Desktop.
Save justhackit/6e2bcb9abe14759333515fa2e2dcd81a to your computer and use it in GitHub Desktop.
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