From aa4419b7e3f4f4d69ea0c8b9390bb38173727e69 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sun, 12 Nov 2023 02:02:06 +0100 Subject: [PATCH] [stdlib] Explicit visibility and return types: Collections --- .../kotlin/kotlin/collections/ArraysNative.kt | 2 +- .../src/kotlin/collections/ArrayList.kt | 12 ++-- .../src/kotlin/collections/CollectionsH.kt | 56 ++++++++++++++++--- .../common/src/kotlin/collections/HashMap.kt | 10 ++-- .../common/src/kotlin/collections/HashSet.kt | 10 ++-- .../src/kotlin/collections/LinkedHashMap.kt | 10 ++-- .../src/kotlin/collections/LinkedHashSet.kt | 10 ++-- .../stdlib/js/src/kotlin/collectionJs.kt | 6 +- .../js/src/kotlin/collections/ArrayList.kt | 2 +- .../js/src/kotlin/collections/HashMap.kt | 10 ++-- .../js/src/kotlin/collections/HashSet.kt | 8 +-- .../src/kotlin/collections/LinkedHashMap.kt | 8 +-- .../src/kotlin/collections/LinkedHashSet.kt | 8 +-- .../jvm/src/kotlin/collections/ArraysJVM.kt | 2 +- .../src/kotlin/collections/CollectionsJVM.kt | 2 +- .../jvm/src/kotlin/collections/TypeAliases.kt | 3 + .../src/kotlin/collections/ArrayList.kt | 12 ++-- .../src/kotlin/collections/Collections.kt | 2 +- .../src/kotlin/collections/HashMap.kt | 12 ++-- .../src/kotlin/collections/HashSet.kt | 14 ++--- .../src/kotlin/collections/Maps.kt | 2 +- .../src/kotlin/collections/ArrayDeque.kt | 4 +- .../wasm/src/kotlin/collections/ArraysWasm.kt | 2 +- 23 files changed, 124 insertions(+), 83 deletions(-) diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArraysNative.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArraysNative.kt index 747b7a53fc5..36fca3d0c2f 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArraysNative.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArraysNative.kt @@ -6,7 +6,7 @@ package kotlin.collections /** - * Returns a *typed* array containing all of the elements of this collection. + * Returns a *typed* array containing all the elements of this collection. * * Allocates an array of runtime type `T` having its size equal to the size of this collection * and populates the array with the elements of this collection. diff --git a/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt b/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt index 56941893002..9e9220afa48 100644 --- a/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt +++ b/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt @@ -5,12 +5,12 @@ package kotlin.collections -expect class ArrayList : MutableList, RandomAccess { +public expect class ArrayList : MutableList, RandomAccess { /** * Creates a new empty [ArrayList]. */ - constructor() + public constructor() /** * Creates a new empty [ArrayList] with the specified initial capacity. @@ -24,17 +24,17 @@ expect class ArrayList : MutableList, RandomAccess { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - constructor(initialCapacity: Int) + public constructor(initialCapacity: Int) /** * Creates a new [ArrayList] filled with the elements of the specified collection. * * The iteration order of elements in the created list is the same as in the specified collection. */ - constructor(elements: Collection) + public constructor(elements: Collection) - fun trimToSize() - fun ensureCapacity(minCapacity: Int) + public fun trimToSize() + public fun ensureCapacity(minCapacity: Int) // From List diff --git a/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt b/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt index b2650ea2c26..d37af544a57 100644 --- a/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt +++ b/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt @@ -5,28 +5,66 @@ package kotlin.collections -expect interface RandomAccess +/** + * Marker interface indicating that the [List] implementation supports fast indexed access. + */ +public expect interface RandomAccess /** * Returns the array if it's not `null`, or an empty array otherwise. * @sample samples.collections.Arrays.Usage.arrayOrEmpty */ -expect inline fun Array?.orEmpty(): Array +public expect inline fun Array?.orEmpty(): Array +/** + * Returns a *typed* array containing all the elements of this collection. + * + * Allocates an array of runtime type `T` having its size equal to the size of this collection + * and populates the array with the elements of this collection. + * @sample samples.collections.Collections.Collections.collectionToTypedArray + */ +public expect inline fun Collection.toTypedArray(): Array -expect inline fun Collection.toTypedArray(): Array - +/** + * Fills the list with the provided [value]. + * + * Each element in the list gets replaced with the [value]. + */ @SinceKotlin("1.2") -expect fun MutableList.fill(value: T): Unit +public expect fun MutableList.fill(value: T): Unit +/** + * Randomly shuffles elements in this list. + * + * See: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm + */ @SinceKotlin("1.2") -expect fun MutableList.shuffle(): Unit +public expect fun MutableList.shuffle(): Unit +/** + * Returns a new list with the elements of this collection randomly shuffled. + */ @SinceKotlin("1.2") -expect fun Iterable.shuffled(): List +public expect fun Iterable.shuffled(): List -expect fun > MutableList.sort(): Unit -expect fun MutableList.sortWith(comparator: Comparator): Unit +/** + * Sorts elements in the list in-place according to their natural sort order. + * + * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. + * + * @sample samples.collections.Collections.Sorting.sortMutableList + */ +public expect fun > MutableList.sort(): Unit + + +/** + * Sorts elements in the list in-place according to the order specified with [comparator]. + * + * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. + * + * @sample samples.collections.Collections.Sorting.sortMutableListWith + */ +public expect fun MutableList.sortWith(comparator: Comparator): Unit // from Grouping.kt diff --git a/libraries/stdlib/common/src/kotlin/collections/HashMap.kt b/libraries/stdlib/common/src/kotlin/collections/HashMap.kt index bcb861cd4d1..9d58cbb5dd3 100644 --- a/libraries/stdlib/common/src/kotlin/collections/HashMap.kt +++ b/libraries/stdlib/common/src/kotlin/collections/HashMap.kt @@ -5,11 +5,11 @@ package kotlin.collections -expect class HashMap : MutableMap { +public expect class HashMap : MutableMap { /** * Creates a new empty [HashMap]. */ - constructor() + public constructor() /** * Creates a new empty [HashMap] with the specified initial capacity. @@ -23,7 +23,7 @@ expect class HashMap : MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - constructor(initialCapacity: Int) + public constructor(initialCapacity: Int) /** * Creates a new empty [HashMap] with the specified initial capacity and load factor. @@ -39,12 +39,12 @@ expect class HashMap : MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - constructor(initialCapacity: Int, loadFactor: Float) + public constructor(initialCapacity: Int, loadFactor: Float) /** * Creates a new [HashMap] filled with the contents of the specified [original] map. */ - constructor(original: Map) + public constructor(original: Map) // From Map diff --git a/libraries/stdlib/common/src/kotlin/collections/HashSet.kt b/libraries/stdlib/common/src/kotlin/collections/HashSet.kt index b9c8d0481b7..d95e222c58e 100644 --- a/libraries/stdlib/common/src/kotlin/collections/HashSet.kt +++ b/libraries/stdlib/common/src/kotlin/collections/HashSet.kt @@ -5,11 +5,11 @@ package kotlin.collections -expect class HashSet : MutableSet { +public expect class HashSet : MutableSet { /** * Creates a new empty [HashSet]. */ - constructor() + public constructor() /** * Creates a new empty [HashSet] with the specified initial capacity. @@ -23,7 +23,7 @@ expect class HashSet : MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - constructor(initialCapacity: Int) + public constructor(initialCapacity: Int) /** * Creates a new empty [HashSet] with the specified initial capacity and load factor. @@ -39,12 +39,12 @@ expect class HashSet : MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - constructor(initialCapacity: Int, loadFactor: Float) + public constructor(initialCapacity: Int, loadFactor: Float) /** * Creates a new [HashSet] filled with the elements of the specified collection. */ - constructor(elements: Collection) + public constructor(elements: Collection) // From Set diff --git a/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt b/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt index a6eb0143142..05cee582b15 100644 --- a/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt +++ b/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt @@ -5,11 +5,11 @@ package kotlin.collections -expect class LinkedHashMap : MutableMap { +public expect class LinkedHashMap : MutableMap { /** * Creates a new empty [LinkedHashMap]. */ - constructor() + public constructor() /** * Creates a new empty [LinkedHashMap] with the specified initial capacity. @@ -23,7 +23,7 @@ expect class LinkedHashMap : MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - constructor(initialCapacity: Int) + public constructor(initialCapacity: Int) /** * Creates a new empty [LinkedHashMap] with the specified initial capacity and load factor. @@ -39,14 +39,14 @@ expect class LinkedHashMap : MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - constructor(initialCapacity: Int, loadFactor: Float) + public constructor(initialCapacity: Int, loadFactor: Float) /** * Creates a new [LinkedHashMap] filled with the contents of the specified [original] map. * * The iteration order of entries in the created map is the same as in the [original] map. */ - constructor(original: Map) + public constructor(original: Map) // From Map diff --git a/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt b/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt index 82f6c1265d3..669474c30ab 100644 --- a/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt +++ b/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt @@ -5,11 +5,11 @@ package kotlin.collections -expect class LinkedHashSet : MutableSet { +public expect class LinkedHashSet : MutableSet { /** * Creates a new empty [LinkedHashSet]. */ - constructor() + public constructor() /** * Creates a new empty [LinkedHashSet] with the specified initial capacity. @@ -23,7 +23,7 @@ expect class LinkedHashSet : MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - constructor(initialCapacity: Int) + public constructor(initialCapacity: Int) /** * Creates a new empty [LinkedHashSet] with the specified initial capacity and load factor. @@ -39,14 +39,14 @@ expect class LinkedHashSet : MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - constructor(initialCapacity: Int, loadFactor: Float) + public constructor(initialCapacity: Int, loadFactor: Float) /** * Creates a new [LinkedHashSet] filled with the elements of the specified collection. * * The iteration order of elements in the created set is the same as in the specified collection. */ - constructor(elements: Collection) + public constructor(elements: Collection) // From Set diff --git a/libraries/stdlib/js/src/kotlin/collectionJs.kt b/libraries/stdlib/js/src/kotlin/collectionJs.kt index 1784a65b4e6..562b46da7af 100644 --- a/libraries/stdlib/js/src/kotlin/collectionJs.kt +++ b/libraries/stdlib/js/src/kotlin/collectionJs.kt @@ -17,7 +17,7 @@ import kotlin.js.arrayBufferIsView public actual inline fun Array?.orEmpty(): Array = this ?: emptyArray() /** - * Returns a *typed* array containing all of the elements of this collection. + * Returns a *typed* array containing all the elements of this collection. * * Allocates an array of runtime type `T` having its size equal to the size of this collection * and populates the array with the elements of this collection. @@ -120,7 +120,7 @@ public actual fun MutableList.fill(value: T): Unit { public actual fun MutableList.shuffle(): Unit = shuffle(Random) /** - * Returns a new list with the elements of this list randomly shuffled. + * Returns a new list with the elements of this collection randomly shuffled. */ @SinceKotlin("1.2") public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } @@ -225,7 +225,7 @@ internal actual fun checkCountOverflow(count: Int): Int { * JS map and set implementations do not make use of capacities or load factors. */ @PublishedApi -internal actual fun mapCapacity(expectedSize: Int) = expectedSize +internal actual fun mapCapacity(expectedSize: Int): Int = expectedSize /** * Checks a collection builder function capacity argument. diff --git a/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt b/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt index 775020afd1f..db4b31d191a 100644 --- a/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt +++ b/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt @@ -161,7 +161,7 @@ public actual open class ArrayList internal constructor(private var array: Ar actual override fun lastIndexOf(element: E): Int = array.lastIndexOf(element) - override fun toString() = arrayToString(array) + override fun toString(): String = arrayToString(array) @Suppress("UNCHECKED_CAST") override fun toArray(array: Array): Array { diff --git a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt index 642a421d11a..51b5e0b84b6 100644 --- a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt @@ -32,7 +32,7 @@ public actual open class HashMap : AbstractMutableMap, MutableMap : AbstractMutableMap, MutableMap : AbstractMutableMap, MutableMap) : this(InternalHashMap(original)) + public actual constructor(original: Map) : this(InternalHashMap(original)) actual override fun clear() { internalMap.clear() @@ -92,7 +92,7 @@ public actual open class HashMap : AbstractMutableMap, MutableMap) = internalMap.putAll(from) + actual override fun putAll(from: Map): Unit = internalMap.putAll(from) } /** diff --git a/libraries/stdlib/js/src/kotlin/collections/HashSet.kt b/libraries/stdlib/js/src/kotlin/collections/HashSet.kt index f2eaf7308e1..e225531cbc9 100644 --- a/libraries/stdlib/js/src/kotlin/collections/HashSet.kt +++ b/libraries/stdlib/js/src/kotlin/collections/HashSet.kt @@ -31,12 +31,12 @@ public actual open class HashSet : AbstractMutableSet, MutableSet { /** * Creates a new empty [HashSet]. */ - actual constructor() : this(InternalHashMap()) + public actual constructor() : this(InternalHashMap()) /** * Creates a new [HashSet] filled with the elements of the specified collection. */ - actual constructor(elements: Collection) : this(InternalHashMap(elements.size)) { + public actual constructor(elements: Collection) : this(InternalHashMap(elements.size)) { for (element in elements) { internalMap.put(element, true) } @@ -56,7 +56,7 @@ public actual open class HashSet : AbstractMutableSet, MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - actual constructor(initialCapacity: Int, loadFactor: Float) : this(InternalHashMap(initialCapacity, loadFactor)) + public actual constructor(initialCapacity: Int, loadFactor: Float) : this(InternalHashMap(initialCapacity, loadFactor)) /** * Creates a new empty [HashSet] with the specified initial capacity. @@ -70,7 +70,7 @@ public actual open class HashSet : AbstractMutableSet, MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - actual constructor(initialCapacity: Int) : this(initialCapacity, 1.0f) + public actual constructor(initialCapacity: Int) : this(initialCapacity, 1.0f) actual override fun add(element: E): Boolean { return internalMap.put(element, true) == null diff --git a/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt b/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt index 169e4829e44..f300c05fa08 100644 --- a/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt @@ -19,7 +19,7 @@ public actual open class LinkedHashMap : HashMap, MutableMap { /** * Creates a new empty [LinkedHashMap]. */ - actual constructor() : super() + public actual constructor() : super() /** * Creates a new empty [LinkedHashMap] with the specified initial capacity. @@ -33,7 +33,7 @@ public actual open class LinkedHashMap : HashMap, MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - actual constructor(initialCapacity: Int) : super(initialCapacity) + public actual constructor(initialCapacity: Int) : super(initialCapacity) /** * Creates a new empty [LinkedHashMap] with the specified initial capacity and load factor. @@ -49,14 +49,14 @@ public actual open class LinkedHashMap : HashMap, MutableMap { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) + public actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) /** * Creates a new [LinkedHashMap] filled with the contents of the specified [original] map. * * The iteration order of entries in the created map is the same as in the [original] map. */ - actual constructor(original: Map) : super(original) + public actual constructor(original: Map) : super(original) internal constructor(internalMap: InternalMap) : super(internalMap) diff --git a/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt b/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt index 8fd0a8ffb98..1005ecc2e6a 100644 --- a/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt +++ b/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt @@ -18,14 +18,14 @@ public actual open class LinkedHashSet : HashSet, MutableSet { /** * Creates a new empty [LinkedHashSet]. */ - actual constructor() : super() + public actual constructor() : super() /** * Creates a new [LinkedHashSet] filled with the elements of the specified collection. * * The iteration order of elements in the created set is the same as in the specified collection. */ - actual constructor(elements: Collection) : super(elements) + public actual constructor(elements: Collection) : super(elements) /** * Creates a new empty [LinkedHashSet] with the specified initial capacity and load factor. @@ -41,7 +41,7 @@ public actual open class LinkedHashSet : HashSet, MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) + public actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) /** * Creates a new empty [LinkedHashSet] with the specified initial capacity. @@ -55,7 +55,7 @@ public actual open class LinkedHashSet : HashSet, MutableSet { * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - actual constructor(initialCapacity: Int) : this(initialCapacity, 1.0f) + public actual constructor(initialCapacity: Int) : this(initialCapacity, 1.0f) internal constructor(internalMap: InternalMap) : super(internalMap) diff --git a/libraries/stdlib/jvm/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/jvm/src/kotlin/collections/ArraysJVM.kt index afd3bf2d929..05e1e058cc4 100644 --- a/libraries/stdlib/jvm/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/collections/ArraysJVM.kt @@ -25,7 +25,7 @@ public actual inline fun Array?.orEmpty(): Array = thi public inline fun ByteArray.toString(charset: Charset): String = String(this, charset) /** - * Returns a *typed* array containing all of the elements of this collection. + * Returns a *typed* array containing all the elements of this collection. * * Allocates an array of runtime type `T` having its size equal to the size of this collection * and populates the array with the elements of this collection. diff --git a/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt b/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt index 1379048fc42..0de9b441905 100644 --- a/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt @@ -63,7 +63,7 @@ public inline fun java.util.Enumeration.toList(): List = java.util.Col /** - * Returns a new list with the elements of this list randomly shuffled. + * Returns a new list with the elements of this collection randomly shuffled. */ @SinceKotlin("1.2") public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } diff --git a/libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt b/libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt index 4a8bcb04204..571e0683aed 100644 --- a/libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt +++ b/libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt @@ -7,6 +7,9 @@ package kotlin.collections +/** + * Marker interface indicating that the [List] implementation supports fast indexed access. + */ @SinceKotlin("1.1") public actual typealias RandomAccess = java.util.RandomAccess diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/ArrayList.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/ArrayList.kt index d3b947c858e..3ade062a066 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/ArrayList.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/ArrayList.kt @@ -5,7 +5,7 @@ package kotlin.collections -actual class ArrayList actual constructor(initialCapacity: Int) : MutableList, RandomAccess, AbstractMutableList() { +public actual class ArrayList public actual constructor(initialCapacity: Int) : MutableList, RandomAccess, AbstractMutableList() { private var backing = arrayOfUninitializedElements(initialCapacity) private var length = 0 private var isReadOnly = false @@ -16,14 +16,14 @@ actual class ArrayList actual constructor(initialCapacity: Int) : MutableList /** * Creates a new empty [ArrayList]. */ - actual constructor() : this(10) + public actual constructor() : this(10) /** * Creates a new [ArrayList] filled with the elements of the specified collection. * * The iteration order of elements in the created list is the same as in the specified collection. */ - actual constructor(elements: Collection) : this(elements.size) { + public actual constructor(elements: Collection) : this(elements.size) { addAll(elements) } @@ -37,7 +37,7 @@ actual class ArrayList actual constructor(initialCapacity: Int) : MutableList override actual val size: Int get() = length - override actual fun isEmpty() = length == 0 + override actual fun isEmpty(): Boolean = length == 0 override actual fun get(index: Int): E { AbstractList.checkElementIndex(index, length) @@ -154,13 +154,13 @@ actual class ArrayList actual constructor(initialCapacity: Int) : MutableList return backing.copyOfRange(fromIndex = 0, toIndex = length) as Array } - actual fun trimToSize() { + public actual fun trimToSize() { registerModification() if (length < backing.size) backing = backing.copyOfUninitializedElements(length) } - final actual fun ensureCapacity(minCapacity: Int) { + public final actual fun ensureCapacity(minCapacity: Int) { if (minCapacity <= backing.size) return registerModification() ensureCapacityInternal(minCapacity) diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/Collections.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/Collections.kt index 67f1540032d..2d0f8087f4a 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/Collections.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/Collections.kt @@ -96,7 +96,7 @@ public actual fun MutableList.shuffle(): Unit { } /** - * Returns a new list with the elements of this list randomly shuffled. + * Returns a new list with the elements of this collection randomly shuffled. */ @SinceKotlin("1.2") public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt index 9876ee30c97..dacdb31255d 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt @@ -9,7 +9,7 @@ import kotlin.native.concurrent.isFrozen import kotlin.native.FreezingIsDeprecated @OptIn(FreezingIsDeprecated::class) -actual class HashMap private constructor( +public actual class HashMap private constructor( // keys in insert order private var keysArray: Array, // values in insert order, allocated only when actually used, always null in pure HashSet @@ -52,7 +52,7 @@ actual class HashMap private constructor( /** * Creates a new empty [HashMap]. */ - actual constructor() : this(INITIAL_CAPACITY) + public actual constructor() : this(INITIAL_CAPACITY) /** * Creates a new empty [HashMap] with the specified initial capacity. @@ -66,7 +66,7 @@ actual class HashMap private constructor( * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - actual constructor(initialCapacity: Int) : this( + public actual constructor(initialCapacity: Int) : this( arrayOfUninitializedElements(initialCapacity), null, IntArray(initialCapacity), @@ -77,7 +77,7 @@ actual class HashMap private constructor( /** * Creates a new [HashMap] filled with the contents of the specified [original] map. */ - actual constructor(original: Map) : this(original.size) { + public actual constructor(original: Map) : this(original.size) { putAll(original) } @@ -95,7 +95,7 @@ actual class HashMap private constructor( * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity) { + public actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity) { require(loadFactor > 0) { "Non-positive load factor: $loadFactor" } } @@ -770,4 +770,4 @@ internal class HashMapEntrySet internal constructor( } // This hash map keeps insertion order. -actual typealias LinkedHashMap = HashMap \ No newline at end of file +public actual typealias LinkedHashMap = HashMap \ No newline at end of file diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/HashSet.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/HashSet.kt index 4ce80562d71..51d3caa6c7c 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/HashSet.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/HashSet.kt @@ -5,7 +5,7 @@ package kotlin.collections -actual class HashSet internal constructor( +public actual class HashSet internal constructor( private val backing: HashMap ) : MutableSet, kotlin.native.internal.KonanSet, AbstractMutableSet() { private companion object { @@ -15,7 +15,7 @@ actual class HashSet internal constructor( /** * Creates a new empty [HashSet]. */ - actual constructor() : this(HashMap()) + public actual constructor() : this(HashMap()) /** * Creates a new empty [HashSet] with the specified initial capacity. @@ -29,12 +29,12 @@ actual class HashSet internal constructor( * * @throws IllegalArgumentException if [initialCapacity] is negative. */ - actual constructor(initialCapacity: Int) : this(HashMap(initialCapacity)) + public actual constructor(initialCapacity: Int) : this(HashMap(initialCapacity)) /** * Creates a new [HashSet] filled with the elements of the specified collection. */ - actual constructor(elements: Collection) : this(elements.size) { + public actual constructor(elements: Collection) : this(elements.size) { addAll(elements) } @@ -52,7 +52,7 @@ actual class HashSet internal constructor( * * @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive. */ - actual constructor(initialCapacity: Int, loadFactor: Float) : this(HashMap(initialCapacity, loadFactor)) + public actual constructor(initialCapacity: Int, loadFactor: Float) : this(HashMap(initialCapacity, loadFactor)) @PublishedApi internal fun build(): Set { @@ -68,7 +68,7 @@ actual class HashSet internal constructor( @Deprecated("This function is not supposed to be used directly.") @DeprecatedSinceKotlin(warningSince = "1.9") // TODO: advance to HIDDEN eventually override fun getElement(element: E): E? = backing.getKey(element) - override actual fun clear() = backing.clear() + override actual fun clear(): Unit = backing.clear() override actual fun add(element: E): Boolean = backing.addKey(element) >= 0 override actual fun remove(element: E): Boolean = backing.removeKey(element) >= 0 override actual fun iterator(): MutableIterator = backing.keysIterator() @@ -90,4 +90,4 @@ actual class HashSet internal constructor( } // This hash set keeps insertion order. -actual typealias LinkedHashSet = HashSet \ No newline at end of file +public actual typealias LinkedHashSet = HashSet \ No newline at end of file diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/Maps.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/Maps.kt index 0b37b203b6c..b3397f261c3 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/Maps.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/Maps.kt @@ -33,7 +33,7 @@ internal actual fun Map.toSingletonMap(): Map * Native map and set implementations do not make use of capacities or load factors. */ @PublishedApi -internal actual fun mapCapacity(expectedSize: Int) = expectedSize +internal actual fun mapCapacity(expectedSize: Int): Int = expectedSize /** * Returns a new read-only map, mapping only the specified key to the diff --git a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt index 1749d6b8219..79dc53f3244 100644 --- a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt +++ b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt @@ -528,7 +528,7 @@ public class ArrayDeque : AbstractMutableList { size = 0 } - @Suppress("NOTHING_TO_OVERRIDE") + @Suppress("NOTHING_TO_OVERRIDE", "NO_EXPLICIT_VISIBILITY_IN_API_MODE") // different visibility inherited from the base class override fun toArray(array: Array): Array { @Suppress("UNCHECKED_CAST") val dest = (if (array.size >= size) array else arrayOfNulls(array, size)) as Array @@ -545,7 +545,7 @@ public class ArrayDeque : AbstractMutableList { return terminateCollectionToArray(size, dest) as Array } - @Suppress("NOTHING_TO_OVERRIDE") + @Suppress("NOTHING_TO_OVERRIDE", "NO_EXPLICIT_VISIBILITY_IN_API_MODE") // different visibility inherited from the base class override fun toArray(): Array { return toArray(arrayOfNulls(size)) } diff --git a/libraries/stdlib/wasm/src/kotlin/collections/ArraysWasm.kt b/libraries/stdlib/wasm/src/kotlin/collections/ArraysWasm.kt index 79a163d2201..236e693d9d9 100644 --- a/libraries/stdlib/wasm/src/kotlin/collections/ArraysWasm.kt +++ b/libraries/stdlib/wasm/src/kotlin/collections/ArraysWasm.kt @@ -6,7 +6,7 @@ package kotlin.collections /** - * Returns a *typed* array containing all of the elements of this collection. + * Returns a *typed* array containing all the elements of this collection. * * Allocates an array of runtime type `T` having its size equal to the size of this collection * and populates the array with the elements of this collection.