7898d167f3
"so that variables declared in loop body are not visible outside of the
loop" (from commit d096f1d)
329 lines
7.7 KiB
Plaintext
Vendored
329 lines
7.7 KiB
Plaintext
Vendored
sealed class ArrayMap<T : Any> : Iterable<T> {
|
|
protected constructor() /* primary */ {
|
|
super/*Any*/()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
abstract val size: Int
|
|
abstract get
|
|
|
|
abstract operator fun set(index: Int, value: T)
|
|
abstract operator fun get(index: Int): T?
|
|
abstract fun copy(): ArrayMap<T>
|
|
|
|
}
|
|
|
|
fun ArrayMap<*>.isEmpty(): Boolean {
|
|
return EQEQ(arg0 = <this>.<get-size>(), arg1 = 0)
|
|
}
|
|
|
|
fun ArrayMap<*>.isNotEmpty(): Boolean {
|
|
return EQEQ(arg0 = <this>.<get-size>(), arg1 = 0).not()
|
|
}
|
|
|
|
internal object EmptyArrayMap : ArrayMap<Nothing> {
|
|
private constructor() /* primary */ {
|
|
super/*ArrayMap*/<Nothing>()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
override val size: Int
|
|
override get(): Int {
|
|
return 0
|
|
}
|
|
|
|
override operator fun set(index: Int, value: Nothing) {
|
|
throw IllegalStateException()
|
|
}
|
|
|
|
override operator fun get(index: Int): Nothing? {
|
|
return null
|
|
}
|
|
|
|
override fun copy(): ArrayMap<Nothing> {
|
|
return <this>
|
|
}
|
|
|
|
override operator fun iterator(): Iterator<Nothing> {
|
|
return { // BLOCK
|
|
local class <no name provided> : Iterator<Nothing> {
|
|
private constructor() /* primary */ {
|
|
super/*Any*/()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
override operator fun hasNext(): Boolean {
|
|
return false
|
|
}
|
|
|
|
override operator fun next(): Nothing {
|
|
return throw NoSuchElementException()
|
|
}
|
|
|
|
}
|
|
|
|
<no name provided>()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
internal class OneElementArrayMap<T : Any> : ArrayMap<T> {
|
|
constructor(value: T, index: Int) /* primary */ {
|
|
super/*ArrayMap*/<T>()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
val value: T
|
|
field = value
|
|
get
|
|
|
|
val index: Int
|
|
field = index
|
|
get
|
|
|
|
override val size: Int
|
|
override get(): Int {
|
|
return 1
|
|
}
|
|
|
|
override operator fun set(index: Int, value: T) {
|
|
throw IllegalStateException()
|
|
}
|
|
|
|
override operator fun get(index: Int): T? {
|
|
return when {
|
|
EQEQ(arg0 = index, arg1 = <this>.<get-index>()) -> <this>.<get-value>()
|
|
else -> null
|
|
}
|
|
}
|
|
|
|
override fun copy(): ArrayMap<T> {
|
|
return OneElementArrayMap<T>(value = <this>.<get-value>(), index = <this>.<get-index>())
|
|
}
|
|
|
|
override operator fun iterator(): Iterator<T> {
|
|
return { // BLOCK
|
|
local class <no name provided> : Iterator<T> {
|
|
private constructor() /* primary */ {
|
|
super/*Any*/()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
private var notVisited: Boolean
|
|
field = true
|
|
private get
|
|
private set
|
|
|
|
override operator fun hasNext(): Boolean {
|
|
return <this>.<get-notVisited>()
|
|
}
|
|
|
|
override operator fun next(): T {
|
|
when {
|
|
<this>.<get-notVisited>() -> { // BLOCK
|
|
<this>.<set-notVisited>(<set-?> = false)
|
|
return <this>.<get-value>()
|
|
}
|
|
else -> throw NoSuchElementException()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
<no name provided>()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
internal class ArrayMapImpl<T : Any> : ArrayMap<T> {
|
|
private constructor(data: Array<Any?>) /* primary */ {
|
|
super/*ArrayMap*/<T>()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
private var data: Array<Any?>
|
|
field = data
|
|
private get
|
|
private set
|
|
|
|
companion object Companion {
|
|
private constructor() /* primary */ {
|
|
super/*Any*/()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
private const val DEFAULT_SIZE: Int
|
|
field = 20
|
|
private get
|
|
|
|
private const val INCREASE_K: Int
|
|
field = 2
|
|
private get
|
|
|
|
}
|
|
|
|
constructor() {
|
|
this/*ArrayMapImpl*/<T>(data = arrayOfNulls<Any>(size = Companion.<get-DEFAULT_SIZE>()))
|
|
}
|
|
|
|
override var size: Int
|
|
field = 0
|
|
override get
|
|
private set
|
|
|
|
private fun ensureCapacity(index: Int) {
|
|
when {
|
|
lessOrEqual(arg0 = <this>.<get-data>().<get-size>(), arg1 = index) -> { // BLOCK
|
|
<this>.<set-data>(<set-?> = <this>.<get-data>().copyOf<Any?>(newSize = <this>.<get-data>().<get-size>().times(other = Companion.<get-INCREASE_K>())))
|
|
}
|
|
}
|
|
}
|
|
|
|
override operator fun set(index: Int, value: T) {
|
|
<this>.ensureCapacity(index = index)
|
|
when {
|
|
EQEQ(arg0 = <this>.<get-data>().get(index = index), arg1 = null) -> { // BLOCK
|
|
val <unary>: Int = <this>.<get-size>()
|
|
<this>.<set-size>(<set-?> = <unary>.inc())
|
|
<unary>
|
|
}
|
|
}
|
|
<this>.<get-data>().set(index = index, value = value)
|
|
}
|
|
|
|
override operator fun get(index: Int): T? {
|
|
return <this>.<get-data>().getOrNull<Any?>(index = index) as T?
|
|
}
|
|
|
|
override fun copy(): ArrayMap<T> {
|
|
return ArrayMapImpl<T>(data = <this>.<get-data>().copyOf<Any?>())
|
|
}
|
|
|
|
override operator fun iterator(): Iterator<T> {
|
|
return { // BLOCK
|
|
local class <no name provided> : AbstractIterator<T> {
|
|
private constructor() /* primary */ {
|
|
super/*AbstractIterator*/<T>()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
private var index: Int
|
|
field = -1
|
|
private get
|
|
private set
|
|
|
|
protected override fun computeNext() {
|
|
{ // BLOCK
|
|
do// COMPOSITE {
|
|
val <unary>: Int = <this>.<get-index>()
|
|
<this>.<set-index>(<set-?> = <unary>.inc())
|
|
<unary>
|
|
// } while (when {
|
|
less(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> EQEQ(arg0 = <this>.<get-data>().get(index = <this>.<get-index>()), arg1 = null)
|
|
else -> false
|
|
})
|
|
}
|
|
when {
|
|
greaterOrEqual(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> <this>.done()
|
|
else -> <this>.setNext(value = <this>.<get-data>().get(index = <this>.<get-index>()) as T)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
<no name provided>()
|
|
}
|
|
}
|
|
|
|
fun remove(index: Int) {
|
|
when {
|
|
EQEQ(arg0 = <this>.<get-data>().get(index = index), arg1 = null).not() -> { // BLOCK
|
|
val <unary>: Int = <this>.<get-size>()
|
|
<this>.<set-size>(<set-?> = <unary>.dec())
|
|
<unary>
|
|
}
|
|
}
|
|
<this>.<get-data>().set(index = index, value = null)
|
|
}
|
|
|
|
fun entries(): List<Entry<T>> {
|
|
return <this>.<get-data>().mapIndexedNotNull<Any?, Entry<T>>(transform = local fun <anonymous>(index: @ParameterName(name = "index") Int, value: Any?): Entry<T>? {
|
|
return when {
|
|
EQEQ(arg0 = value, arg1 = null).not() -> Entry<T>(key = index, value = value as T)
|
|
else -> null
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
data class Entry<T : Any?> : Entry<Int, T> {
|
|
constructor(key: Int, value: T) /* primary */ {
|
|
super/*Any*/()
|
|
/* <init>() */
|
|
|
|
}
|
|
|
|
override val key: Int
|
|
field = key
|
|
override get
|
|
|
|
override val value: T
|
|
field = value
|
|
override get
|
|
|
|
operator fun component1(): Int {
|
|
return <this>.#key
|
|
}
|
|
|
|
operator fun component2(): T {
|
|
return <this>.#value
|
|
}
|
|
|
|
fun copy(key: Int = <this>.#key, value: T = <this>.#value): Entry<T> {
|
|
return Entry<Any>(key = key, value = value)
|
|
}
|
|
|
|
override fun equals(other: Any?): Boolean {
|
|
when {
|
|
EQEQEQ(arg0 = <this>, arg1 = other) -> return true
|
|
}
|
|
when {
|
|
other !is Entry<T> -> return false
|
|
}
|
|
val tmp0_other_with_cast: Entry<T> = other as Entry<T>
|
|
when {
|
|
EQEQ(arg0 = <this>.#key, arg1 = tmp0_other_with_cast.#key).not() -> return false
|
|
}
|
|
when {
|
|
EQEQ(arg0 = <this>.#value, arg1 = tmp0_other_with_cast.#value).not() -> return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
override fun hashCode(): Int {
|
|
var result: Int = <this>.#key.hashCode()
|
|
result = result.times(other = 31).plus(other = when {
|
|
EQEQ(arg0 = <this>.#value, arg1 = null) -> 0
|
|
else -> <this>.#value.hashCode()
|
|
})
|
|
return result
|
|
}
|
|
|
|
override fun toString(): String {
|
|
return "Entry(" + "key=" + <this>.#key + ", " + "value=" + <this>.#value + ")"
|
|
}
|
|
|
|
}
|
|
|
|
}
|