com.jtransc.ds.Allocator.kt Maven / Gradle / Ivy
package com.jtransc.ds
class Allocator {
private var lastIndex = 0;
private val _array = arrayListOf()
private val map = hashMapOf()
val array: List = _array
fun allocateOnce(value: T): Int {
if (value !in map) {
map[value] = lastIndex++
_array += value
}
return map[value]!!
}
}