Decouple add from nextFreeIndex in IdMap

This commit is contained in:
DBotThePony 2024-05-22 19:04:37 +07:00
parent 5769cff60b
commit e2d27e34a5
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -19,7 +19,7 @@ class IdMap<T : Any>(val min: Int = 0, val max: Int = Int.MAX_VALUE, private val
return nextIndex
}
fun add(value: T): Int {
fun nextFreeIndex(): Int {
var i = 0
var index = next()
@ -41,6 +41,11 @@ class IdMap<T : Any>(val min: Int = 0, val max: Int = Int.MAX_VALUE, private val
}
}
return index
}
fun add(value: T): Int {
val index = nextFreeIndex()
map[index] = value
return index
}