Align behavoir of collection constructors across platforms #KT-59192

The initialCapacity should be non-negative and loadFactor should be positive.

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-08 15:25:07 +03:00
committed by Space Team
parent 0bef1533e2
commit 830c78773c
9 changed files with 91 additions and 7 deletions
@@ -77,7 +77,9 @@ actual class HashMap<K, V> private constructor(
*
* @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive.
*/
actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity)
actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity) {
require(loadFactor > 0) { "Non-positive load factor: $loadFactor" }
}
@PublishedApi
internal fun build(): Map<K, V> {
@@ -52,7 +52,7 @@ actual class HashSet<E> internal constructor(
*
* @throws IllegalArgumentException if [initialCapacity] is negative or [loadFactor] is non-positive.
*/
actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity)
actual constructor(initialCapacity: Int, loadFactor: Float) : this(HashMap<E, Nothing>(initialCapacity, loadFactor))
@PublishedApi
internal fun build(): Set<E> {