Add ir interpreter tests
This commit is contained in:
committed by
TeamCityServer
parent
cc2d7340dc
commit
e28ab45c51
+234
@@ -0,0 +1,234 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("ArraysKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
public operator fun <T> Array<out T>.contains(element: T): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun ByteArray.contains(element: Byte): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun ShortArray.contains(element: Short): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun IntArray.contains(element: Int): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun LongArray.contains(element: Long): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun BooleanArray.contains(element: Boolean): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun CharArray.contains(element: Char): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.indexOf(element: T): Int {
|
||||
if (element == null) {
|
||||
for (index in indices) {
|
||||
if (this[index] == null) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun ByteArray.indexOf(element: Byte): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun ShortArray.indexOf(element: Short): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun IntArray.indexOf(element: Int): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun LongArray.indexOf(element: Long): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun BooleanArray.indexOf(element: Boolean): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun CharArray.indexOf(element: Char): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
public actual fun <T> Array<out T>.asList(): List<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun ByteArray.asList(): List<Byte> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun ShortArray.asList(): List<Short> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun IntArray.asList(): List<Int> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun LongArray.asList(): List<Long> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun FloatArray.asList(): List<Float> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun DoubleArray.asList(): List<Double> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun BooleanArray.asList(): List<Boolean> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun CharArray.asList(): List<Char> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public val <T> Array<out T>.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val ByteArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val ShortArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val IntArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val LongArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val FloatArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val DoubleArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val BooleanArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val CharArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public inline fun <T> Array<out T>.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
public val <T> Array<out T>.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val ByteArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val ShortArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val IntArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val LongArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val FloatArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val DoubleArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val BooleanArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val CharArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
|
||||
public fun ByteArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun ShortArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun IntArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun LongArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public inline fun ByteArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun ShortArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun IntArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun LongArray.isEmpty(): Boolean = size == 0
|
||||
|
||||
public fun <T> Array<out T>.toList(): List<T> {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
public fun IntArray.toList(): List<Int> {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.toMutableList(): MutableList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public fun IntArray.toMutableList(): MutableList<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.toSet(): Set<T> {
|
||||
return when (size) {
|
||||
0 -> emptySet()
|
||||
1 -> setOf(this[0])
|
||||
else -> toCollection(LinkedHashSet<T>(mapCapacity(size)))
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Array<out T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.asSequence(): Sequence<T> {
|
||||
if (isEmpty()) return emptySequence()
|
||||
return Sequence { this.iterator() }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("CharsKt")
|
||||
|
||||
package kotlin.text
|
||||
|
||||
public actual fun Char.isWhitespace(): Boolean = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
@@ -0,0 +1,176 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("CollectionsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
internal object EmptyIterator : ListIterator<Nothing> {
|
||||
override fun hasNext(): Boolean = false
|
||||
override fun hasPrevious(): Boolean = false
|
||||
override fun nextIndex(): Int = 0
|
||||
override fun previousIndex(): Int = -1
|
||||
override fun next(): Nothing = throw NoSuchElementException()
|
||||
override fun previous(): Nothing = throw NoSuchElementException()
|
||||
}
|
||||
|
||||
internal object EmptyList : List<Nothing>, Serializable, RandomAccess {
|
||||
private const val serialVersionUID: Long = -7390468764508069838L
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is List<*> && other.isEmpty()
|
||||
override fun hashCode(): Int = 1
|
||||
override fun toString(): String = "[]"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Empty list doesn't contain element at index $index.")
|
||||
override fun indexOf(element: Nothing): Int = -1
|
||||
override fun lastIndexOf(element: Nothing): Int = -1
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
override fun listIterator(): ListIterator<Nothing> = EmptyIterator
|
||||
override fun listIterator(index: Int): ListIterator<Nothing> {
|
||||
if (index != 0) throw IndexOutOfBoundsException("Index: $index")
|
||||
return EmptyIterator
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> {
|
||||
if (fromIndex == 0 && toIndex == 0) return this
|
||||
throw IndexOutOfBoundsException("fromIndex: $fromIndex, toIndex: $toIndex")
|
||||
}
|
||||
|
||||
private fun readResolve(): Any = EmptyList
|
||||
}
|
||||
|
||||
public fun <T> emptyList(): List<T> = EmptyList
|
||||
|
||||
public fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()
|
||||
|
||||
public inline fun <T> listOf(): List<T> = emptyList()
|
||||
|
||||
public inline fun <T> mutableListOf(): MutableList<T> = ArrayList()
|
||||
|
||||
public inline fun <T> arrayListOf(): ArrayList<T> = ArrayList()
|
||||
|
||||
public fun <T> mutableListOf(vararg elements: T): MutableList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T> arrayListOf(vararg elements: T): ArrayList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T : Any> listOfNotNull(element: T?): List<T> = if (element != null) listOf(element) else emptyList()
|
||||
|
||||
public inline fun <T> List(size: Int, init: (index: Int) -> T): List<T> = MutableList(size, init)
|
||||
|
||||
public inline fun <T> MutableList(size: Int, init: (index: Int) -> T): MutableList<T> {
|
||||
val list = ArrayList<T>(size)
|
||||
repeat(size) { index -> list.add(init(index)) }
|
||||
return list
|
||||
}
|
||||
|
||||
public val Collection<*>.indices: IntRange
|
||||
get() = 0..size - 1
|
||||
|
||||
public val <T> List<T>.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
|
||||
public inline fun <T> Collection<T>.isNotEmpty(): Boolean = !isEmpty()
|
||||
|
||||
public inline fun <T> List<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public fun <T> List<T>.first(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("List is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.single(): T {
|
||||
when (this) {
|
||||
is List -> return this.single()
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
val single = iterator.next()
|
||||
if (iterator.hasNext())
|
||||
throw IllegalArgumentException("Collection has more than one element.")
|
||||
return single
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> List<T>.single(): T {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("List is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("List has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.toList(): List<T> {
|
||||
if (this is Collection) {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(if (this is List) get(0) else iterator().next())
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
return this.toMutableList().optimizeReadOnlyList()
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.toMutableList(): MutableList<T> {
|
||||
if (this is Collection<T>)
|
||||
return this.toMutableList()
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
public fun <T> Collection<T>.toMutableList(): MutableList<T> {
|
||||
return ArrayList(this)
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this
|
||||
}
|
||||
|
||||
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
||||
if (this is Collection && isEmpty()) return true
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Iterable<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("MapsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
import kotlin.sequences.*
|
||||
|
||||
private object EmptyMap : Map<Any?, Nothing>, Serializable {
|
||||
private const val serialVersionUID: Long = 8246714829545688274
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is Map<*, *> && other.isEmpty()
|
||||
override fun hashCode(): Int = 0
|
||||
override fun toString(): String = "{}"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
|
||||
override fun containsKey(key: Any?): Boolean = false
|
||||
override fun containsValue(value: Nothing): Boolean = false
|
||||
override fun get(key: Any?): Nothing? = null
|
||||
override val entries: Set<Map.Entry<Any?, Nothing>> get() = EmptySet
|
||||
override val keys: Set<Any?> get() = EmptySet
|
||||
override val values: Collection<Nothing> get() = EmptyList
|
||||
|
||||
private fun readResolve(): Any = EmptyMap
|
||||
}
|
||||
|
||||
public fun <K, V> emptyMap(): Map<K, V> = @Suppress("UNCHECKED_CAST") (EmptyMap as Map<K, V>)
|
||||
|
||||
public fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> =
|
||||
if (pairs.size > 0) pairs.toMap(LinkedHashMap(mapCapacity(pairs.size))) else emptyMap()
|
||||
|
||||
public inline fun <K, V> mapOf(): Map<K, V> = emptyMap()
|
||||
|
||||
public inline fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
|
||||
|
||||
public fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>): MutableMap<K, V> =
|
||||
LinkedHashMap<K, V>(mapCapacity(pairs.size)).apply { putAll(pairs) }
|
||||
|
||||
public inline fun <K, V> hashMapOf(): HashMap<K, V> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <K, V> hashMapOf(vararg pairs: Pair<K, V>): HashMap<K, V> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public inline fun <K, V> linkedMapOf(): LinkedHashMap<K, V> = LinkedHashMap<K, V>()
|
||||
|
||||
internal fun mapCapacity(expectedSize: Int): Int = when {
|
||||
// We are not coercing the value to a valid one and not throwing an exception. It is up to the caller to
|
||||
// properly handle negative values.
|
||||
expectedSize < 0 -> expectedSize
|
||||
expectedSize < 3 -> expectedSize + 1
|
||||
expectedSize < 1 shl (Int.SIZE_BITS - 2) -> ((expectedSize / 0.75F) + 1.0F).toInt()
|
||||
// any large value
|
||||
else -> Int.MAX_VALUE
|
||||
}
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.contains(key: K): Boolean = containsKey(key)
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.get(key: K): V? = (this as Map<K, V>).get(key)
|
||||
|
||||
public inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit {
|
||||
put(key, value)
|
||||
}
|
||||
|
||||
public inline fun <K> Map<out K, *>.containsKey(key: K): Boolean = (this as Map<K, *>).containsKey(key)
|
||||
|
||||
public inline fun <K, V> Map<K, V>.containsValue(value: V): Boolean = this.containsValue(value)
|
||||
|
||||
public inline fun <K, V> MutableMap<out K, V>.remove(key: K): V? = (this as MutableMap<K, V>).remove(key)
|
||||
|
||||
public inline operator fun <K, V> Map.Entry<K, V>.component1(): K = key
|
||||
|
||||
public inline operator fun <K, V> Map.Entry<K, V>.component2(): V = value
|
||||
|
||||
public inline fun <K, V> Map.Entry<K, V>.toPair(): Pair<K, V> = Pair(key, value)
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.iterator(): Iterator<Map.Entry<K, V>> = entries.iterator()
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Array<out Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Iterable<Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Sequence<Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> Iterable<Pair<K, V>>.toMap(): Map<K, V> {
|
||||
if (this is Collection) {
|
||||
return when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> mapOf(if (this is List) this[0] else iterator().next())
|
||||
else -> toMap(LinkedHashMap<K, V>(mapCapacity(size)))
|
||||
}
|
||||
}
|
||||
return toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap()
|
||||
}
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Iterable<Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
public fun <K, V> Array<out Pair<K, V>>.toMap(): Map<K, V> = when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> mapOf(this[0])
|
||||
else -> toMap(LinkedHashMap<K, V>(mapCapacity(size)))
|
||||
}
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Array<out Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
public fun <K, V> Sequence<Pair<K, V>>.toMap(): Map<K, V> = toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap()
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Sequence<Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
internal fun <K, V> Map<K, V>.optimizeReadOnlyMap() = when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> this // toSingletonMapOrSelf()
|
||||
else -> this
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("RangesKt")
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
public infix fun Int.until(to: Byte): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Byte): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
public infix fun Char.until(to: Char): CharRange {
|
||||
if (to <= '\u0000') return CharRange.EMPTY
|
||||
return this .. (to - 1).toChar()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this .. (to - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Int): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Long.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Short.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Short): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Short): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("SequencesKt")
|
||||
|
||||
package kotlin.sequences
|
||||
|
||||
public inline fun <T> Sequence(crossinline iterator: () -> Iterator<T>): Sequence<T> = object : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = iterator()
|
||||
}
|
||||
|
||||
public fun <T> Iterator<T>.asSequence(): Sequence<T> = Sequence { this }//.constrainOnce()
|
||||
|
||||
public fun <T> sequenceOf(vararg elements: T): Sequence<T> = if (elements.isEmpty()) emptySequence() else elements.asSequence()
|
||||
|
||||
public fun <T> emptySequence(): Sequence<T> = EmptySequence
|
||||
|
||||
private object EmptySequence : Sequence<Nothing>, DropTakeSequence<Nothing> {
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
override fun drop(n: Int) = EmptySequence
|
||||
override fun take(n: Int) = EmptySequence
|
||||
}
|
||||
|
||||
public inline fun <T> Sequence<T>?.orEmpty(): Sequence<T> = this ?: emptySequence()
|
||||
|
||||
private class GeneratorSequence<T : Any>(private val getInitialValue: () -> T?, private val getNextValue: (T) -> T?) : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = object : Iterator<T> {
|
||||
var nextItem: T? = null
|
||||
var nextState: Int = -2 // -2 for initial unknown, -1 for next unknown, 0 for done, 1 for continue
|
||||
|
||||
private fun calcNext() {
|
||||
nextItem = if (nextState == -2) getInitialValue() else getNextValue(nextItem!!)
|
||||
nextState = if (nextItem == null) 0 else 1
|
||||
}
|
||||
|
||||
override fun next(): T {
|
||||
if (nextState < 0)
|
||||
calcNext()
|
||||
|
||||
if (nextState == 0)
|
||||
throw NoSuchElementException()
|
||||
val result = nextItem as T
|
||||
// Do not clean nextItem (to avoid keeping reference on yielded instance) -- need to keep state for getNextValue
|
||||
nextState = -1
|
||||
return result
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
if (nextState < 0)
|
||||
calcNext()
|
||||
return nextState == 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T : Any> generateSequence(nextFunction: () -> T?): Sequence<T> {
|
||||
return GeneratorSequence(nextFunction, { nextFunction() })//.constrainOnce()
|
||||
}
|
||||
|
||||
public fun <T : Any> generateSequence(seed: T?, nextFunction: (T) -> T?): Sequence<T> =
|
||||
if (seed == null)
|
||||
EmptySequence
|
||||
else
|
||||
GeneratorSequence({ seed }, nextFunction)
|
||||
|
||||
public fun <T : Any> generateSequence(seedFunction: () -> T?, nextFunction: (T) -> T?): Sequence<T> =
|
||||
GeneratorSequence(seedFunction, nextFunction)
|
||||
|
||||
public operator fun <T> Sequence<T>.contains(element: T): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.indexOf(element: T): Int {
|
||||
var index = 0
|
||||
for (item in this) {
|
||||
checkIndexOverflow(index)
|
||||
if (element == item)
|
||||
return index
|
||||
index++
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.toList(): List<T> {
|
||||
return this.toMutableList().optimizeReadOnlyList()
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.toMutableList(): MutableList<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Sequence<T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("SetsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
internal object EmptySet : Set<Nothing>, Serializable {
|
||||
private const val serialVersionUID: Long = 3406603774387020532
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is Set<*> && other.isEmpty()
|
||||
override fun hashCode(): Int = 0
|
||||
override fun toString(): String = "[]"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
|
||||
private fun readResolve(): Any = EmptySet
|
||||
}
|
||||
|
||||
public fun <T> emptySet(): Set<T> = EmptySet
|
||||
|
||||
public fun <T> setOf(vararg elements: T): Set<T> = if (elements.size > 0) elements.toSet() else emptySet()
|
||||
|
||||
public inline fun <T> setOf(): Set<T> = emptySet()
|
||||
|
||||
public inline fun <T> mutableSetOf(): MutableSet<T> = LinkedHashSet()
|
||||
|
||||
public fun <T> mutableSetOf(vararg elements: T): MutableSet<T> = elements.toCollection(LinkedHashSet(mapCapacity(elements.size)))
|
||||
|
||||
public inline fun <T> hashSetOf(): HashSet<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T> hashSetOf(vararg elements: T): HashSet<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
internal fun <T> Set<T>.optimizeReadOnlySet() = when (size) {
|
||||
0 -> emptySet()
|
||||
1 -> setOf(iterator().next())
|
||||
else -> this
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.*
|
||||
|
||||
public inline fun <R> run(block: () -> R): R {
|
||||
return block()
|
||||
}
|
||||
|
||||
public inline fun <T, R> T.run(block: T.() -> R): R {
|
||||
return block()
|
||||
}
|
||||
|
||||
public inline fun <T, R> with(receiver: T, block: T.() -> R): R {
|
||||
return receiver.block()
|
||||
}
|
||||
|
||||
public inline fun <T> T.apply(block: T.() -> Unit): T {
|
||||
block()
|
||||
return this
|
||||
}
|
||||
|
||||
public inline fun <T> T.also(block: (T) -> Unit): T {
|
||||
block(this)
|
||||
return this
|
||||
}
|
||||
|
||||
public inline fun <T, R> T.let(block: (T) -> R): R {
|
||||
return block(this)
|
||||
}
|
||||
|
||||
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? {
|
||||
return if (predicate(this)) this else null
|
||||
}
|
||||
|
||||
public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
|
||||
return if (!predicate(this)) this else null
|
||||
}
|
||||
|
||||
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
||||
for (index in 0 until times) {
|
||||
action(index)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("StringsKt")
|
||||
|
||||
package kotlin.text
|
||||
|
||||
public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence {
|
||||
var startIndex = 0
|
||||
var endIndex = length - 1
|
||||
var startFound = false
|
||||
|
||||
while (startIndex <= endIndex) {
|
||||
val index = if (!startFound) startIndex else endIndex
|
||||
val match = predicate(this[index])
|
||||
|
||||
if (!startFound) {
|
||||
if (!match)
|
||||
startFound = true
|
||||
else
|
||||
startIndex += 1
|
||||
} else {
|
||||
if (!match)
|
||||
break
|
||||
else
|
||||
endIndex -= 1
|
||||
}
|
||||
}
|
||||
|
||||
return subSequence(startIndex, endIndex + 1)
|
||||
}
|
||||
|
||||
public fun CharSequence.trim(): CharSequence = trim(Char::isWhitespace)
|
||||
|
||||
public inline fun String.trim(): String = (this as CharSequence).trim().toString()
|
||||
|
||||
public inline fun CharSequence.isEmpty(): Boolean = length == 0
|
||||
|
||||
public inline fun CharSequence.isNotEmpty(): Boolean = length > 0
|
||||
|
||||
public operator fun CharSequence.iterator(): CharIterator = object : CharIterator() {
|
||||
private var index = 0
|
||||
|
||||
public override fun nextChar(): Char = get(index++)
|
||||
|
||||
public override fun hasNext(): Boolean = index < length
|
||||
}
|
||||
|
||||
public fun CharSequence.first(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Char sequence is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public val CharSequence.indices: IntRange
|
||||
get() = 0..length - 1
|
||||
|
||||
public val CharSequence.lastIndex: Int
|
||||
get() = this.length - 1
|
||||
|
||||
public inline fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString()
|
||||
|
||||
public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.endInclusive + 1).toString()
|
||||
|
||||
public inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public fun CharSequence.toList(): List<Char> {
|
||||
return when (length) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
|
||||
public fun CharSequence.toMutableList(): MutableList<Char> {
|
||||
return toCollection(ArrayList<Char>(length))
|
||||
}
|
||||
|
||||
public fun <C : MutableCollection<in Char>> CharSequence.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("UArraysKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
public inline fun UIntArray.elementAtOrElse(index: Int, defaultValue: (Int) -> UInt): UInt {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public inline val UIntArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val ULongArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val UByteArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val UShortArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
|
||||
public inline val UIntArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val ULongArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val UByteArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val UShortArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
|
||||
public inline fun UIntArray.first(): UInt {
|
||||
return storage.first().toUInt()
|
||||
}
|
||||
public inline fun ULongArray.first(): ULong {
|
||||
return storage.first().toULong()
|
||||
}
|
||||
public inline fun UByteArray.first(): UByte {
|
||||
return storage.first().toUByte()
|
||||
}
|
||||
public inline fun UShortArray.first(): UShort {
|
||||
return storage.first().toUShort()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package kotlin
|
||||
|
||||
public inline infix fun Byte.and(other: Byte): Byte = (this.toInt() and other.toInt()).toByte()
|
||||
public inline infix fun Byte.or(other: Byte): Byte = (this.toInt() or other.toInt()).toByte()
|
||||
public inline infix fun Byte.xor(other: Byte): Byte = (this.toInt() xor other.toInt()).toByte()
|
||||
public inline fun Byte.inv(): Byte = (this.toInt().inv()).toByte()
|
||||
|
||||
public inline infix fun Short.and(other: Short): Short = (this.toInt() and other.toInt()).toShort()
|
||||
public inline infix fun Short.or(other: Short): Short = (this.toInt() or other.toInt()).toShort()
|
||||
public inline infix fun Short.xor(other: Short): Short = (this.toInt() xor other.toInt()).toShort()
|
||||
public inline fun Short.inv(): Short = (this.toInt().inv()).toShort()
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package kotlin
|
||||
|
||||
public inline val Char.code: Int get() = this.toInt()
|
||||
|
||||
expect fun Double.isNaN(): Boolean
|
||||
expect fun Float.isNaN(): Boolean
|
||||
|
||||
public data class Pair<out A, out B>(public val first: A, public val second: B) : Serializable {
|
||||
public override fun toString(): String = "($first, $second)"
|
||||
}
|
||||
|
||||
public infix fun <A, B> A.to(that: B): Pair<A, B> = Pair(this, that)
|
||||
|
||||
public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
|
||||
|
||||
public data class Triple<out A, out B, out C>(
|
||||
public val first: A, public val second: B, public val third: C
|
||||
) : Serializable {
|
||||
public override fun toString(): String = "($first, $second, $third)"
|
||||
}
|
||||
|
||||
public fun <T> Triple<T, T, T>.toList(): List<T> = listOf(first, second, third)
|
||||
|
||||
public fun checkIndexOverflow(index: Int): Int {
|
||||
if (index < 0) {
|
||||
throw kotlin.ArithmeticException("Index overflow has happened.")
|
||||
}
|
||||
return index
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package kotlin.experimental
|
||||
|
||||
//Will return file and line number there this function was called
|
||||
inline fun sourceLocation(): String = throw kotlin.UnsupportedOperationException("Implemented as intrinsic")
|
||||
Reference in New Issue
Block a user