From 06e6168a7302501bf203ca4cc0f0d53bd8b5bc9d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 3 Aug 2023 18:36:17 +0700 Subject: [PATCH] Faster version of Container.balance --- src/main/kotlin/ru/dbotthepony/mc/otm/container/Ext.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/Ext.kt index d74d6220b..1029bdbff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/Ext.kt @@ -263,7 +263,7 @@ fun Container.balance(slots: IntRange) { 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" } var any = false @@ -277,3 +277,10 @@ fun Container.balance(startSlot: Int = 0, endSlot: Int = containerSize - 1) { if (!any) return 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) +}