Updated MazeFinder and supporting structures to improve performance and implement tools for the PathFinder
parent
8f274458a9
commit
6a06ba20d3
@ -1,49 +0,0 @@
|
||||
package technology.zim.util
|
||||
|
||||
import kotlin.random.Random
|
||||
|
||||
class TrimmableArrayList<E> {
|
||||
val data = ArrayList<E>()
|
||||
|
||||
fun addAll(c: Collection<E>) {
|
||||
data.addAll(c)
|
||||
}
|
||||
|
||||
fun isNotEmpty(): Boolean {
|
||||
return data.isNotEmpty()
|
||||
}
|
||||
|
||||
fun isEmpty(): Boolean {
|
||||
return data.isEmpty()
|
||||
}
|
||||
|
||||
fun add(item: E) {
|
||||
data.add(item)
|
||||
|
||||
}
|
||||
|
||||
fun size():Int {
|
||||
return data.size
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
data.clear()
|
||||
}
|
||||
|
||||
fun removeAt(index: Int) {
|
||||
data[index] = data[data.size - 1]
|
||||
data.removeLast()
|
||||
}
|
||||
|
||||
//O(n) remove operation
|
||||
fun remove(item: E) {
|
||||
data[data.indexOf(item)] = data[data.size - 1]
|
||||
data.removeLast()
|
||||
}
|
||||
|
||||
|
||||
fun random(): E {
|
||||
return data[Random.nextInt(data.size)]
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
import technology.zim.data.Tile
|
||||
import technology.zim.util.TrimmableArrayList
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
|
||||
class TrimmableArrayListTest {
|
||||
|
||||
@Test
|
||||
fun emptyTest() {
|
||||
val empty = TrimmableArrayList<Tile>()
|
||||
assert(empty.isEmpty())
|
||||
|
||||
empty.add(Tile(0, 0))
|
||||
empty.remove(Tile(0, 0))
|
||||
assert(empty.isEmpty())
|
||||
|
||||
empty.addAll(listOf(Tile(0, 0), Tile(1, 1), Tile(2, 2)))
|
||||
assert(empty.isNotEmpty())
|
||||
|
||||
empty.remove(Tile(0, 0))
|
||||
println("realSize: " + empty.size() + " Size: " + empty.data.size)
|
||||
assert(empty.size() == 2)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue