More of stdlib (#363)

This commit is contained in:
Nikolay Igotti
2017-03-21 09:36:11 +03:00
committed by GitHub
parent 3820ea0724
commit a15be29519
2 changed files with 570 additions and 0 deletions
+457
View File
@@ -316,6 +316,367 @@ private class BooleanIteratorImpl(val collection: BooleanArray) : BooleanIterato
// This part is from generated _Arrays.kt.
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun <T> Array<out T>.component1(): T {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component1(): Byte {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component1(): Short {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component1(): Int {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component1(): Long {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component1(): Float {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component1(): Double {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component1(): Boolean {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component1(): Char {
return get(0)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun <T> Array<out T>.component2(): T {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component2(): Byte {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component2(): Short {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component2(): Int {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component2(): Long {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component2(): Float {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component2(): Double {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component2(): Boolean {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component2(): Char {
return get(1)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun <T> Array<out T>.component3(): T {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component3(): Byte {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component3(): Short {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component3(): Int {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component3(): Long {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component3(): Float {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component3(): Double {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component3(): Boolean {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component3(): Char {
return get(2)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun <T> Array<out T>.component4(): T {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component4(): Byte {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component4(): Short {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component4(): Int {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component4(): Long {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component4(): Float {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component4(): Double {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component4(): Boolean {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component4(): Char {
return get(3)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun <T> Array<out T>.component5(): T {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component5(): Byte {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component5(): Short {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component5(): Int {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component5(): Long {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component5(): Float {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component5(): Double {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component5(): Boolean {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component5(): Char {
return get(4)
}
/**
* Returns `true` if all elements match the given [predicate].
*/
@@ -1765,6 +2126,102 @@ public fun <@kotlin.internal.OnlyInputTypes T> Array<out T>.lastIndexOf(element:
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun ByteArray.lastIndexOf(element: Byte): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun ShortArray.lastIndexOf(element: Short): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun IntArray.lastIndexOf(element: Int): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun LongArray.lastIndexOf(element: Long): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun FloatArray.lastIndexOf(element: Float): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun DoubleArray.lastIndexOf(element: Double): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun BooleanArray.lastIndexOf(element: Boolean): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun CharArray.lastIndexOf(element: Char): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Appends all elements to the given [destination] collection.
*/
@@ -160,6 +160,119 @@ public fun <T> Array<out T>.asList(): List<T> {
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun ByteArray.asList(): List<Byte> {
return object : AbstractList<Byte>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Byte): Boolean = this@asList.contains(element)
override fun get(index: Int): Byte = this@asList[index]
override fun indexOf(element: Byte): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Byte): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun ShortArray.asList(): List<Short> {
return object : AbstractList<Short>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Short): Boolean = this@asList.contains(element)
override fun get(index: Int): Short = this@asList[index]
override fun indexOf(element: Short): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Short): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun IntArray.asList(): List<Int> {
return object : AbstractList<Int>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Int): Boolean = this@asList.contains(element)
override fun get(index: Int): Int = this@asList[index]
override fun indexOf(element: Int): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Int): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun LongArray.asList(): List<Long> {
return object : AbstractList<Long>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Long): Boolean = this@asList.contains(element)
override fun get(index: Int): Long = this@asList[index]
override fun indexOf(element: Long): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Long): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun FloatArray.asList(): List<Float> {
return object : AbstractList<Float>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Float): Boolean = this@asList.contains(element)
override fun get(index: Int): Float = this@asList[index]
override fun indexOf(element: Float): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Float): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun DoubleArray.asList(): List<Double> {
return object : AbstractList<Double>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Double): Boolean = this@asList.contains(element)
override fun get(index: Int): Double = this@asList[index]
override fun indexOf(element: Double): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Double): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun BooleanArray.asList(): List<Boolean> {
return object : AbstractList<Boolean>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Boolean): Boolean = this@asList.contains(element)
override fun get(index: Int): Boolean = this@asList[index]
override fun indexOf(element: Boolean): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Boolean): Int = this@asList.lastIndexOf(element)
}
}
/**
* Returns a [List] that wraps the original array.
*/
public fun CharArray.asList(): List<Char> {
return object : AbstractList<Char>(), RandomAccess {
override val size: Int get() = this@asList.size
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(element: Char): Boolean = this@asList.contains(element)
override fun get(index: Int): Char = this@asList[index]
override fun indexOf(element: Char): Int = this@asList.indexOf(element)
override fun lastIndexOf(element: Char): Int = this@asList.lastIndexOf(element)
}
}
fun <E> Array<E>.toSet(): Set<E> {
val result = HashSet<E>(this.size)
for (e in this) {