Generate arrays of unsigned types

This commit is contained in:
Ilya Gorbunov
2018-05-03 21:36:44 +03:00
parent 4fbc48f83f
commit 5c6719b1e6
5 changed files with 232 additions and 0 deletions
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
// Auto-generated file. DO NOT EDIT!
package kotlin
public inline class UShortArray internal constructor(private val storage: ShortArray) : Collection<UShort> {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): UShort = storage[index].toUShort()
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: UShort) {
storage[index] = value.toShort()
}
/** Returns the number of elements in the array. */
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): UShortIterator = Iterator(storage)
private class Iterator(private val array: ShortArray) : UShortIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextUShort() = if (index < array.size) array[index++].toUShort() else throw NoSuchElementException(index.toString())
}
override fun contains(element: UShort): Boolean = storage.contains(element.toShort())
override fun containsAll(elements: Collection<UShort>): Boolean = elements.all { storage.contains(it.toShort()) }
override fun isEmpty(): Boolean = this.storage.size == 0
}
public /*inline*/ fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray {
return UShortArray(ShortArray(size) { index -> init(index).toShort() })
}
public fun ushortArrayOf(vararg elements: UShort): UShortArray {
return UShortArray(elements.size) { index -> elements[index] }
}