Skip to content

Commit d9b4251

Browse files
authored
Collection immutable (3): fill in missing @param, @tparam, and @return tags in Scaladoc comments (#25373)
As a next step in improving the Scaladoc documentation for the Scala 3 standard library, this PR fills in missing @param, @tparam, and @return tags for collection immutable.
1 parent 9cfa0dd commit d9b4251

25 files changed

Lines changed: 860 additions & 86 deletions

library-js/src/scala/collection/immutable/NumericRange.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,18 @@ sealed class NumericRange[T](
9595

9696
/** Creates a new range with the start and end values of this range and
9797
* a new `step`.
98+
*
99+
* @param newStep the new step value for the resulting range
98100
*/
99101
def by(newStep: T): NumericRange[T] = copy(start, end, newStep)
100102

101103

102-
/** Creates a copy of this range. */
104+
/** Creates a copy of this range.
105+
*
106+
* @param start the first value of the new range
107+
* @param end the upper bound of the new range (inclusive or exclusive, matching the original range)
108+
* @param step the step value between successive elements of the new range
109+
*/
103110
def copy(start: T, end: T, step: T): NumericRange[T] =
104111
new NumericRange(start, end, step, isInclusive)
105112

@@ -350,6 +357,13 @@ object NumericRange {
350357
/** Calculates the number of elements in a range given start, end, step, and
351358
* whether or not it is inclusive. Throws an exception if step == 0 or
352359
* the number of elements exceeds the maximum Int.
360+
*
361+
* @tparam T the numeric type of the range elements, which must have an `Integral` instance
362+
* @param start the first value in the range
363+
* @param end the end boundary of the range (exclusive or inclusive depending on `isInclusive`)
364+
* @param step the increment between successive elements
365+
* @param isInclusive whether `end` is included in the range
366+
* @param num the `Integral` instance used for arithmetic on `T`
353367
*/
354368
def count[T](start: T, end: T, step: T, isInclusive: Boolean)(implicit num: Integral[T]): Int = {
355369
val zero = num.zero

library-js/src/scala/collection/immutable/Range.scala

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ sealed abstract class Range(
160160
/** Creates a new range with the `start` and `end` values of this range and
161161
* a new `step`.
162162
*
163+
* @param step the new step value for the range; must be non-zero
163164
* @return a new range with a different step
164165
*/
165166
final def by(step: Int): Range = copy(start, end, step)
@@ -258,6 +259,9 @@ sealed abstract class Range(
258259
/** Creates a new range consisting of the last `n` elements of the range.
259260
*
260261
* $doesNotUseBuilders
262+
*
263+
* @param n the number of elements to take from the end of this range
264+
* @return a new range consisting of the last `n` elements, or the entire range if `n` is greater than the range length
261265
*/
262266
final override def takeRight(n: Int): Range = {
263267
if (n <= 0) newEmptyRange(start)
@@ -274,6 +278,9 @@ sealed abstract class Range(
274278
/** Creates a new range consisting of the initial `length - n` elements of the range.
275279
*
276280
* $doesNotUseBuilders
281+
*
282+
* @param n the number of elements to drop from the end of this range
283+
* @return a new range consisting of all elements except the last `n`, or an empty range if `n` is greater than the range length
277284
*/
278285
final override def dropRight(n: Int): Range = {
279286
if (n <= 0) this
@@ -536,6 +543,11 @@ object Range {
536543
* precondition: step != 0
537544
* If the size of the range exceeds Int.MaxValue, the
538545
* result will be negative.
546+
*
547+
* @param start the first element of the range
548+
* @param end the end boundary of the range (inclusive or exclusive depending on `isInclusive`)
549+
* @param step the increment between successive elements; must be non-zero
550+
* @param isInclusive whether `end` is included in the range
539551
*/
540552
def count(start: Int, end: Int, step: Int, isInclusive: Boolean): Int = {
541553
if (step == 0)
@@ -565,18 +577,34 @@ object Range {
565577

566578
/** Makes a range from `start` until `end` (exclusive) with given step value.
567579
* @note step != 0
580+
*
581+
* @param start the first element of the range
582+
* @param end the exclusive upper bound of the range
583+
* @param step the increment between successive elements; must be non-zero
568584
*/
569585
def apply(start: Int, end: Int, step: Int): Range.Exclusive = new Range.Exclusive(start, end, step)
570586

571-
/** Makes a range from `start` until `end` (exclusive) with step value 1. */
587+
/** Makes a range from `start` until `end` (exclusive) with step value 1.
588+
*
589+
* @param start the first element of the range
590+
* @param end the exclusive upper bound of the range
591+
*/
572592
def apply(start: Int, end: Int): Range.Exclusive = new Range.Exclusive(start, end, 1)
573593

574594
/** Makes an inclusive range from `start` to `end` with given step value.
575595
* @note step != 0
596+
*
597+
* @param start the first element of the range
598+
* @param end the inclusive upper bound of the range
599+
* @param step the increment between successive elements; must be non-zero
576600
*/
577601
def inclusive(start: Int, end: Int, step: Int): Range.Inclusive = new Range.Inclusive(start, end, step)
578602

579-
/** Makes an inclusive range from `start` to `end` with step value 1. */
603+
/** Makes an inclusive range from `start` to `end` with step value 1.
604+
*
605+
* @param start the first element of the range
606+
* @param end the inclusive upper bound of the range
607+
*/
580608
def inclusive(start: Int, end: Int): Range.Inclusive = new Range.Inclusive(start, end, 1)
581609

582610
@SerialVersionUID(3L)

library/src/scala/collection/immutable/ArraySeq.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import scala.util.hashing.MurmurHash3
3333
*
3434
* @define coll immutable array
3535
* @define Coll `ArraySeq`
36+
*
37+
* @tparam A the element type of the immutable array
3638
*/
3739
sealed abstract class ArraySeq[+A]
3840
extends AbstractSeq[A]
@@ -90,7 +92,9 @@ sealed abstract class ArraySeq[+A]
9092

9193
/** Fast concatenation of two [[ArraySeq]]s.
9294
*
93-
* @return null if optimisation not possible.
95+
* @tparam B the element type of the resulting sequence, a supertype of `A`
96+
* @param that the `ArraySeq` to append to this sequence
97+
* @return the concatenated `ArraySeq`, or `null` if optimization is not possible
9498
*/
9599
private def appendedAllArraySeq[B >: A](that: ArraySeq[B]): ArraySeq[B] | Null = {
96100
// Optimise concatenation of two ArraySeqs
@@ -310,6 +314,10 @@ object ArraySeq extends StrictOptimizedClassTagSeqFactory[ArraySeq] { self =>
310314
* boxed, the resulting instance is an [[ArraySeq.ofRef]]. Writing
311315
* `ArraySeq.unsafeWrapArray(a.asInstanceOf[Array[Int]])` does not work, it throws a
312316
* `ClassCastException` at runtime.
317+
*
318+
* @tparam T the element type of the array to wrap
319+
* @param x the array to wrap, which must not be modified after wrapping
320+
* @return an `ArraySeq` backed by the given array, using the appropriate primitive specialization
313321
*/
314322
def unsafeWrapArray[T](x: Array[T]): ArraySeq[T] = ((x: @unchecked) match {
315323
case null => null

library/src/scala/collection/immutable/BitSet.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ sealed abstract class BitSet
6565
} else this
6666
}
6767

68-
/** Updates word at index `idx`; enlarges set if `idx` outside range of set. */
68+
/** Updates word at index `idx`; enlarges set if `idx` outside range of set.
69+
*
70+
* @param idx the index of the word to update
71+
* @param w the new value for the word at index `idx`
72+
*/
6973
protected def updateWord(idx: Int, w: Long): BitSet
7074

7175
override def map(f: Int => Int): BitSet = strictOptimizedMap(newSpecificBuilder, f)
@@ -108,7 +112,10 @@ object BitSet extends SpecificIterableFactory[Int, BitSet] {
108112

109113
private def createSmall(a: Long, b: Long): BitSet = if (b == 0L) new BitSet1(a) else new BitSet2(a, b)
110114

111-
/** A bitset containing all the bits in an array. */
115+
/** A bitset containing all the bits in an array.
116+
*
117+
* @param elems the array of `Long` words representing the bits; the array is defensively copied
118+
*/
112119
def fromBitMask(elems: Array[Long]): BitSet = {
113120
val len = elems.length
114121
if (len == 0) empty
@@ -122,6 +129,8 @@ object BitSet extends SpecificIterableFactory[Int, BitSet] {
122129

123130
/** A bitset containing all the bits in an array, wrapping the existing
124131
* array without copying.
132+
*
133+
* @param elems the array of `Long` words representing the bits; the caller must not modify the array after this call
125134
*/
126135
def fromBitMaskNoCopy(elems: Array[Long]): BitSet = {
127136
val len = elems.length

library/src/scala/collection/immutable/ChampCommon.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private[collection] abstract class Node[T <: Node[T]] {
105105
* node before traversing sub-nodes (left to right).
106106
*
107107
* @tparam T the trie node type we are iterating over
108+
* @tparam A the element type produced by the iterator
108109
*/
109110
private[immutable] abstract class ChampBaseIterator[A, T <: Node[T]] extends AbstractIterator[A] {
110111

@@ -191,6 +192,7 @@ private[immutable] abstract class ChampBaseIterator[A, T <: Node[T]] extends Abs
191192
* iterator performs a depth-first post-order traversal, traversing sub-nodes (right to left).
192193
*
193194
* @tparam T the trie node type we are iterating over
195+
* @tparam A the element type produced by the iterator
194196
*/
195197
private[immutable] abstract class ChampBaseReverseIterator[A, T <: Node[T]] extends AbstractIterator[A] {
196198

library/src/scala/collection/immutable/HashMap.scala

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ final class HashMap[K, +V] private[immutable] (private[immutable] val rootNode:
274274

275275
override def foreachEntry[U](f: (K, V) => U): Unit = rootNode.foreachEntry(f)
276276

277-
/** Applies a function to each key, value, and **original** hash value in this Map. */
277+
/** Applies a function to each key, value, and **original** hash value in this Map.
278+
*
279+
* @param f the function to apply to each key, value, and original hash triple
280+
*/
278281
@inline private[collection] def foreachWithHash(f: (K, V, Int) => Unit): Unit = rootNode.foreachWithHash(f)
279282

280283
override def equals(that: Any): Boolean =
@@ -336,6 +339,8 @@ final class HashMap[K, +V] private[immutable] (private[immutable] val rootNode:
336339
* // HashMap(2 -> 1) is returned, but it could also have returned HashMap(2 -> 3)
337340
* ```
338341
*
342+
*
343+
* @tparam V1 the value type of the resulting HashMap, a supertype of `V`
339344
*/
340345
def merged[V1 >: V](that: HashMap[K, V1])(mergef: ((K, V), (K, V1)) => (K, V1)): HashMap[K, V1] =
341346
if (mergef == null) {
@@ -555,16 +560,18 @@ private[immutable] sealed abstract class MapNode[K, +V] extends Node[MapNode[K,
555560

556561
/** Returns a MapNode with the passed key-value assignment added
557562
*
563+
* @tparam V1 the value type of the returned node, a supertype of `V`
558564
* @param key the key to add to the MapNode
559565
* @param value the value to associate with `key`
560-
* @param originalHash the original hash of `key`
566+
* @param originalHash the original hash code of `key` (via `key.##`)
561567
* @param hash the improved hash of `key`
562568
* @param shift the shift of the node (distanceFromRoot * BitPartitionSize)
563569
* @param replaceValue if true, then the value currently associated to `key` will be replaced with the passed value
564570
* argument.
565571
* if false, then the key will be inserted if not already present, however if the key is present
566572
* then the passed value will not replace the current value. That is, if `false`, then this
567573
* method has `update if not exists` semantics.
574+
* @return a new `MapNode` containing the updated key-value mapping
568575
*/
569576
def updated[V1 >: V](key: K, value: V1, originalHash: Int, hash: Int, shift: Int, replaceValue: Boolean): MapNode[K, V1]
570577

@@ -606,17 +613,30 @@ private[immutable] sealed abstract class MapNode[K, +V] extends Node[MapNode[K,
606613
*
607614
* `this` should be a node from `left` hashmap in `left.merged(right)(mergef)`
608615
*
616+
* @tparam V1 the value type of the merged result, a supertype of `V`
609617
* @param that node from the "right" HashMap. Must also be at the same "path" or "position" within the right tree,
610618
* as `this` is, within the left tree
619+
* @param builder the builder used to accumulate the merged key-value pairs
620+
* @param shift the bit-level offset into the hash code, equal to `depth * BitPartitionSize`
621+
* @param mergef the function used to resolve collisions between keys present in both nodes
611622
*/
612623
def mergeInto[V1 >: V](that: MapNode[K, V1], builder: HashMapBuilder[K, V1], shift: Int)(mergef: ((K, V), (K, V1)) => (K, V1)): Unit
613624

614625
/** Returns the exact (equal by reference) key, and value, associated to a given key.
615626
* If the key is not bound to a value, then an exception is thrown
627+
*
628+
* @param key the key to look up
629+
* @param originalHash the original hash code of `key` (via `key.##`)
630+
* @param hash the improved hash of `key`
631+
* @param shift the bit-level offset into the hash code, equal to `depth * BitPartitionSize`
616632
*/
617633
def getTuple(key: K, originalHash: Int, hash: Int, shift: Int): (K, V)
618634

619-
/** Adds all key-value pairs to a builder. */
635+
/** Adds all key-value pairs to a builder.
636+
*
637+
* @tparam V1 the value type of the target builder, a supertype of `V`
638+
* @param builder the builder to add the key-value pairs to
639+
*/
620640
def buildTo[V1 >: V](builder: HashMapBuilder[K, V1]): Unit
621641
}
622642

@@ -784,13 +804,15 @@ private final class BitmapIndexedMapNode[K, +V](
784804
* If instead this method may not mutate the child node in which the to-be-updated key-value pair belongs, then
785805
* that child will be updated immutably, but the result will be mutably re-inserted as a child of this node.
786806
*
807+
* @tparam V1 the value type of the updated node, a supertype of `V`
787808
* @param key the key to update
788809
* @param value the value to set `key` to
789810
* @param originalHash key.##
790811
* @param keyHash the improved hash
812+
*
791813
* @param shallowlyMutableNodeMap bitmap of child nodes of this node, which can be shallowly mutated
792814
* during the call to this method
793-
*
815+
* @param shift the bit-level offset into the hash code, equal to `depth * BitPartitionSize`
794816
* @return Int which is the bitwise OR of shallowlyMutableNodeMap and any freshly created nodes, which will be
795817
* available for mutations in subsequent calls.
796818
*/
@@ -1023,6 +1045,7 @@ private final class BitmapIndexedMapNode[K, +V](
10231045

10241046
/** Variant of `copyAndMigrateFromInlineToNode` which mutates `this` rather than returning a new node.
10251047
*
1048+
* @tparam V1 the value type of the child node, a supertype of `V`
10261049
* @param bitpos the bit position of the data to migrate to node
10271050
* @param keyHash the improved hash of the key currently at `bitpos`
10281051
* @param node the node to place at `bitpos` beneath `this`
@@ -2171,9 +2194,17 @@ private final class MapKeyValueTupleHashIterator[K, V](rootNode: MapNode[K, V])
21712194
}
21722195
}
21732196

2174-
/** Used in HashMap[K, V]#removeAll(HashSet[K]). */
2197+
/** Used in HashMap[K, V]#removeAll(HashSet[K]).
2198+
*
2199+
* @tparam K the key type
2200+
* @param rootSetNode the root node of the `HashSet` whose keys are to be removed
2201+
*/
21752202
private final class MapNodeRemoveAllSetNodeIterator[K](rootSetNode: SetNode[K]) extends ChampBaseIterator[K, SetNode[K]](rootSetNode) {
2176-
/** Returns the result of immutably removing all keys in `rootSetNode` from `rootMapNode`. */
2203+
/** Returns the result of immutably removing all keys in `rootSetNode` from `rootMapNode`.
2204+
*
2205+
* @tparam V the value type of the map node
2206+
* @param rootMapNode the root node of the map from which keys will be removed
2207+
*/
21772208
def removeAll[V](rootMapNode: BitmapIndexedMapNode[K, V]): BitmapIndexedMapNode[K, V] = {
21782209
var curr = rootMapNode
21792210
while (curr.size > 0 && hasNext) {
@@ -2214,13 +2245,19 @@ object HashMap extends MapFactory[HashMap] {
22142245

22152246
/** Creates a new Builder which can be reused after calling `result()` without an
22162247
* intermediate call to `clear()` in order to build multiple related results.
2248+
*
2249+
* @tparam K the key type of the HashMap
2250+
* @tparam V the value type of the HashMap
22172251
*/
22182252
def newBuilder[K, V]: ReusableBuilder[(K, V), HashMap[K, V]] = new HashMapBuilder[K, V]
22192253
}
22202254

22212255

22222256
/** A `Builder` for a `HashMap`.
22232257
* $multipleResults
2258+
*
2259+
* @tparam K the key type of the HashMap being built
2260+
* @tparam V the value type of the HashMap being built
22242261
*/
22252262
private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K, V), HashMap[K, V]] {
22262263
import MapNode._
@@ -2247,7 +2284,12 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
22472284
rootNode.getOrElse(key, originalHash, improve(originalHash), 0, value)
22482285
}
22492286

2250-
/** Inserts element `elem` into array `as` at index `ix`, shifting right the trailing elems. */
2287+
/** Inserts element `elem` into array `as` at index `ix`, shifting right the trailing elems.
2288+
*
2289+
* @param as the source array to insert into
2290+
* @param ix the zero-based index at which to insert `elem`
2291+
* @param elem the element to insert
2292+
*/
22512293
private def insertElement(as: Array[Int], ix: Int, elem: Int): Array[Int] = {
22522294
if (ix < 0) throw new ArrayIndexOutOfBoundsException
22532295
if (ix > as.length) throw new ArrayIndexOutOfBoundsException
@@ -2258,7 +2300,16 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
22582300
result
22592301
}
22602302

2261-
/** Inserts key-value into the bitmapIndexMapNode. Requires that this is a new key-value pair. */
2303+
/** Inserts key-value into the bitmapIndexMapNode. Requires that this is a new key-value pair.
2304+
*
2305+
* @tparam V1 the value type being inserted, a supertype of `V`
2306+
* @param bm the bitmap-indexed map node to mutate
2307+
* @param bitpos the bit position in the bitmap where the key-value pair should be inserted
2308+
* @param key the key to insert
2309+
* @param originalHash the original hash code of `key` (via `key.##`)
2310+
* @param keyHash the improved hash of `key`
2311+
* @param value the value to associate with `key`
2312+
*/
22622313
private def insertValue[V1 >: V](bm: BitmapIndexedMapNode[K, V],bitpos: Int, key: K, originalHash: Int, keyHash: Int, value: V1): Unit = {
22632314
val dataIx = bm.dataIndex(bitpos)
22642315
val idx = TupleLength * dataIx
@@ -2281,7 +2332,15 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
22812332
bm.cachedJavaKeySetHashCode += keyHash
22822333
}
22832334

2284-
/** Upserts a key/value pair into mapNode, mutably. */
2335+
/** Upserts a key/value pair into mapNode, mutably.
2336+
*
2337+
* @param mapNode the map node to update in place
2338+
* @param key the key to insert or update
2339+
* @param value the value to associate with `key`
2340+
* @param originalHash the original hash code of `key` (via `key.##`)
2341+
* @param keyHash the improved hash of `key`
2342+
* @param shift the bit-level offset into the hash code, equal to `depth * BitPartitionSize`
2343+
*/
22852344
private[immutable] def update(mapNode: MapNode[K, V], key: K, value: V, originalHash: Int, keyHash: Int, shift: Int): Unit = {
22862345
mapNode match {
22872346
case bm: BitmapIndexedMapNode[K, V] =>

0 commit comments

Comments
 (0)