All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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]!!
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy