Skip to content

Commit

Permalink
aggressive vertical compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-git committed May 9, 2024
1 parent de57d6e commit b91708c
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 386 deletions.
21 changes: 10 additions & 11 deletions src/main/scala/com/evolution/resourcepool/IntHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ private[resourcepool] object IntHelper {

implicit class IntOpsIntHelper(val self: Int) extends AnyVal {

def divide(value: Int): List[Int] =
if (value <= 0 || self <= 0) {
List.empty
} else if (value >= self) {
def divide(divisor: Int): List[Int] =
if (divisor <= 0 || self <= 0)
Nil
else if (divisor >= self)
List.fill(self)(1)
} else if (value == 1) {
else if (divisor == 1)
List(self)
} else {
val quotient = (self.toDouble / value).round.toInt
else {
val quotient = (self.toDouble / divisor).round.toInt

@tailrec
def loop(self: Int, value: Int, result: List[Int]): List[Int] =
if (self > quotient && value > 1) {
if (self > quotient && value > 1)
loop(self - quotient, value - 1, quotient :: result)
} else {
else
(self :: result).reverse
}

loop(self, value, List.empty)
loop(self, divisor, List.empty)
}
}
}
Loading

0 comments on commit b91708c

Please sign in to comment.