Faster version of Container.balance
This commit is contained in:
parent
20d478cbfb
commit
06e6168a73
@ -263,7 +263,7 @@ fun Container.balance(slots: IntRange) {
|
|||||||
balance(IntArraySet().also { it.addAll(slots) })
|
balance(IntArraySet().also { it.addAll(slots) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Container.balance(startSlot: Int = 0, endSlot: Int = containerSize - 1) {
|
fun Container.balance(startSlot: Int, endSlot: Int) {
|
||||||
require(startSlot <= endSlot) { "Invalid slot range: $startSlot .. $endSlot" }
|
require(startSlot <= endSlot) { "Invalid slot range: $startSlot .. $endSlot" }
|
||||||
var any = false
|
var any = false
|
||||||
|
|
||||||
@ -277,3 +277,10 @@ fun Container.balance(startSlot: Int = 0, endSlot: Int = containerSize - 1) {
|
|||||||
if (!any) return
|
if (!any) return
|
||||||
balance(IntArraySet(endSlot - startSlot + 1).also { for (i in startSlot .. endSlot) it.add(i) }, false)
|
balance(IntArraySet(endSlot - startSlot + 1).also { for (i in startSlot .. endSlot) it.add(i) }, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Container.balance() {
|
||||||
|
if (isEmpty)
|
||||||
|
return
|
||||||
|
|
||||||
|
balance(IntArraySet(containerSize).also { for (i in 0 until containerSize) it.add(i) }, false)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user