[stdlib] Explicit visibility and return types: Collections
This commit is contained in:
committed by
Space Team
parent
0dd61c9f81
commit
aa4419b7e3
@@ -5,7 +5,7 @@
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
actual class ArrayList<E> actual constructor(initialCapacity: Int) : MutableList<E>, RandomAccess, AbstractMutableList<E>() {
|
||||
public actual class ArrayList<E> public actual constructor(initialCapacity: Int) : MutableList<E>, RandomAccess, AbstractMutableList<E>() {
|
||||
private var backing = arrayOfUninitializedElements<E>(initialCapacity)
|
||||
private var length = 0
|
||||
private var isReadOnly = false
|
||||
@@ -16,14 +16,14 @@ actual class ArrayList<E> 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<E>) : this(elements.size) {
|
||||
public actual constructor(elements: Collection<E>) : this(elements.size) {
|
||||
addAll(elements)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ actual class ArrayList<E> 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<E> actual constructor(initialCapacity: Int) : MutableList
|
||||
return backing.copyOfRange(fromIndex = 0, toIndex = length) as Array<Any?>
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -96,7 +96,7 @@ public actual fun <T> MutableList<T>.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 <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply { shuffle() }
|
||||
|
||||
@@ -9,7 +9,7 @@ import kotlin.native.concurrent.isFrozen
|
||||
import kotlin.native.FreezingIsDeprecated
|
||||
|
||||
@OptIn(FreezingIsDeprecated::class)
|
||||
actual class HashMap<K, V> private constructor(
|
||||
public actual class HashMap<K, V> private constructor(
|
||||
// keys in insert order
|
||||
private var keysArray: Array<K>,
|
||||
// values in insert order, allocated only when actually used, always null in pure HashSet
|
||||
@@ -52,7 +52,7 @@ actual class HashMap<K, V> 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<K, V> 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<K, V> private constructor(
|
||||
/**
|
||||
* Creates a new [HashMap] filled with the contents of the specified [original] map.
|
||||
*/
|
||||
actual constructor(original: Map<out K, V>) : this(original.size) {
|
||||
public actual constructor(original: Map<out K, V>) : this(original.size) {
|
||||
putAll(original)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ 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) {
|
||||
public actual constructor(initialCapacity: Int, loadFactor: Float) : this(initialCapacity) {
|
||||
require(loadFactor > 0) { "Non-positive load factor: $loadFactor" }
|
||||
}
|
||||
|
||||
@@ -770,4 +770,4 @@ internal class HashMapEntrySet<K, V> internal constructor(
|
||||
}
|
||||
|
||||
// This hash map keeps insertion order.
|
||||
actual typealias LinkedHashMap<K, V> = HashMap<K, V>
|
||||
public actual typealias LinkedHashMap<K, V> = HashMap<K, V>
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
actual class HashSet<E> internal constructor(
|
||||
public actual class HashSet<E> internal constructor(
|
||||
private val backing: HashMap<E, *>
|
||||
) : MutableSet<E>, kotlin.native.internal.KonanSet<E>, AbstractMutableSet<E>() {
|
||||
private companion object {
|
||||
@@ -15,7 +15,7 @@ actual class HashSet<E> internal constructor(
|
||||
/**
|
||||
* Creates a new empty [HashSet].
|
||||
*/
|
||||
actual constructor() : this(HashMap<E, Nothing>())
|
||||
public actual constructor() : this(HashMap<E, Nothing>())
|
||||
|
||||
/**
|
||||
* Creates a new empty [HashSet] with the specified initial capacity.
|
||||
@@ -29,12 +29,12 @@ actual class HashSet<E> internal constructor(
|
||||
*
|
||||
* @throws IllegalArgumentException if [initialCapacity] is negative.
|
||||
*/
|
||||
actual constructor(initialCapacity: Int) : this(HashMap<E, Nothing>(initialCapacity))
|
||||
public actual constructor(initialCapacity: Int) : this(HashMap<E, Nothing>(initialCapacity))
|
||||
|
||||
/**
|
||||
* Creates a new [HashSet] filled with the elements of the specified collection.
|
||||
*/
|
||||
actual constructor(elements: Collection<E>) : this(elements.size) {
|
||||
public actual constructor(elements: Collection<E>) : this(elements.size) {
|
||||
addAll(elements)
|
||||
}
|
||||
|
||||
@@ -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(HashMap<E, Nothing>(initialCapacity, loadFactor))
|
||||
public actual constructor(initialCapacity: Int, loadFactor: Float) : this(HashMap<E, Nothing>(initialCapacity, loadFactor))
|
||||
|
||||
@PublishedApi
|
||||
internal fun build(): Set<E> {
|
||||
@@ -68,7 +68,7 @@ actual class HashSet<E> 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<E> = backing.keysIterator()
|
||||
@@ -90,4 +90,4 @@ actual class HashSet<E> internal constructor(
|
||||
}
|
||||
|
||||
// This hash set keeps insertion order.
|
||||
actual typealias LinkedHashSet<V> = HashSet<V>
|
||||
public actual typealias LinkedHashSet<V> = HashSet<V>
|
||||
@@ -33,7 +33,7 @@ internal actual fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V>
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user