summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-11-24 10:17:40 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2015-11-24 10:17:40 +0100
commit86300fe1b3ab87b2e40616ed78709e8f03e707b5 (patch)
tree4458169015b02ecf7e29f805d0dbd6645171620a /src/library
parent3d0cbf9d10416fab8017b5fb46af44f59ee89fd1 (diff)
parent8eb1d4c29d85aef7828eeb35169e80c085cea93e (diff)
downloadscala-86300fe1b3ab87b2e40616ed78709e8f03e707b5.tar.gz
scala-86300fe1b3ab87b2e40616ed78709e8f03e707b5.tar.bz2
scala-86300fe1b3ab87b2e40616ed78709e8f03e707b5.zip
Merge commit '8eb1d4c' into merge-2.11-to-2.12-nov-24
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/BitSetLike.scala2
-rw-r--r--src/library/scala/collection/GenMapLike.scala3
-rw-r--r--src/library/scala/collection/GenTraversableLike.scala20
-rw-r--r--src/library/scala/collection/GenTraversableOnce.scala86
-rw-r--r--src/library/scala/collection/Iterator.scala2
-rw-r--r--src/library/scala/collection/LinearSeqOptimized.scala2
-rw-r--r--src/library/scala/collection/MapLike.scala8
-rw-r--r--src/library/scala/collection/Traversable.scala2
-rw-r--r--src/library/scala/collection/TraversableLike.scala36
-rw-r--r--src/library/scala/collection/TraversableOnce.scala13
-rw-r--r--src/library/scala/collection/TraversableProxyLike.scala2
-rw-r--r--src/library/scala/collection/generic/TraversableForwarder.scala2
-rw-r--r--src/library/scala/collection/immutable/HashMap.scala4
-rw-r--r--src/library/scala/collection/immutable/HashSet.scala6
-rw-r--r--src/library/scala/collection/immutable/IntMap.scala2
-rw-r--r--src/library/scala/collection/immutable/List.scala26
-rw-r--r--src/library/scala/collection/immutable/LongMap.scala2
-rw-r--r--src/library/scala/collection/immutable/Map.scala8
-rw-r--r--src/library/scala/collection/immutable/PagedSeq.scala3
-rw-r--r--src/library/scala/collection/immutable/Stream.scala6
-rw-r--r--src/library/scala/collection/immutable/TreeMap.scala2
-rw-r--r--src/library/scala/collection/immutable/TreeSet.scala2
-rw-r--r--src/library/scala/collection/immutable/Vector.scala2
-rw-r--r--src/library/scala/collection/mutable/AnyRefMap.scala122
-rw-r--r--src/library/scala/collection/mutable/ArraySeq.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayStack.scala2
-rw-r--r--src/library/scala/collection/mutable/HashMap.scala6
-rw-r--r--src/library/scala/collection/mutable/HashSet.scala2
-rw-r--r--src/library/scala/collection/mutable/ImmutableSetAdaptor.scala2
-rw-r--r--src/library/scala/collection/mutable/LinkedListLike.scala2
-rw-r--r--src/library/scala/collection/mutable/LongMap.scala126
-rw-r--r--src/library/scala/collection/mutable/SetLike.scala4
-rw-r--r--src/library/scala/collection/mutable/SynchronizedSet.scala2
-rw-r--r--src/library/scala/collection/package.scala38
-rw-r--r--src/library/scala/collection/parallel/ParIterableLike.scala1
-rw-r--r--src/library/scala/collection/parallel/ParMapLike.scala8
36 files changed, 278 insertions, 280 deletions
diff --git a/src/library/scala/collection/BitSetLike.scala b/src/library/scala/collection/BitSetLike.scala
index 8a8af79151..29369447d1 100644
--- a/src/library/scala/collection/BitSetLike.scala
+++ b/src/library/scala/collection/BitSetLike.scala
@@ -115,7 +115,7 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
else Iterator.empty.next()
}
- override def foreach[B](f: Int => B) {
+ override def foreach[U](f: Int => U) {
/* NOTE: while loops are significantly faster as of 2.11 and
one major use case of bitsets is performance. Also, there
is nothing to do when all bits are clear, so use that as
diff --git a/src/library/scala/collection/GenMapLike.scala b/src/library/scala/collection/GenMapLike.scala
index bce9740522..2b39fa2289 100644
--- a/src/library/scala/collection/GenMapLike.scala
+++ b/src/library/scala/collection/GenMapLike.scala
@@ -124,8 +124,7 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
}
}
} catch {
- case ex: ClassCastException =>
- println("class cast "); false
+ case ex: ClassCastException => false
}}
case _ =>
false
diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala
index 8b9d3e7a17..d730996be2 100644
--- a/src/library/scala/collection/GenTraversableLike.scala
+++ b/src/library/scala/collection/GenTraversableLike.scala
@@ -158,18 +158,6 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
@migration("The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse.", "2.9.0")
def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
- /** Applies a function `f` to all elements of this $coll.
- *
- * @param f the function that is applied for its side-effect to every element.
- * The result of function `f` is discarded.
- *
- * @tparam U the type parameter describing the result of function `f`.
- * This result will always be ignored. Typically `U` is `Unit`,
- * but this is not necessary.
- *
- * @usecase def foreach(f: A => Unit): Unit
- * @inheritdoc
- */
def foreach[U](f: A => U): Unit
/** Builds a new collection by applying a function to all elements of this $coll.
@@ -269,16 +257,16 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
* {{{
* scala> val a = List(1)
* a: List[Int] = List(1)
- *
+ *
* scala> val b = List(2)
* b: List[Int] = List(2)
- *
+ *
* scala> val c = a ++ b
* c: List[Int] = List(1, 2)
- *
+ *
* scala> val d = List('a')
* d: List[Char] = List(a)
- *
+ *
* scala> val e = c ++ d
* e: List[AnyVal] = List(1, 2, a)
* }}}
diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala
index a45ec965f5..244ff26397 100644
--- a/src/library/scala/collection/GenTraversableOnce.scala
+++ b/src/library/scala/collection/GenTraversableOnce.scala
@@ -49,6 +49,22 @@ import scala.language.higherKinds
*/
trait GenTraversableOnce[+A] extends Any {
+ /** Applies a function `f` to all elements of this $coll.
+ *
+ * @param f the function that is applied for its side-effect to every element.
+ * The result of function `f` is discarded.
+ *
+ * @tparam U the type parameter describing the result of function `f`.
+ * This result will always be ignored. Typically `U` is `Unit`,
+ * but this is not necessary.
+ *
+ * @usecase def foreach(f: A => Unit): Unit
+ * @inheritdoc
+ *
+ * Note: this method underlies the implementation of most other bulk operations.
+ * It's important to implement this method in an efficient way.
+ *
+ */
def foreach[U](f: A => U): Unit
def hasDefiniteSize: Boolean
@@ -110,13 +126,14 @@ trait GenTraversableOnce[+A] extends Any {
* binary operator.
*
* $undefinedorder
+ * $willNotTerminateInf
*
* @tparam A1 a type parameter for the binary operator, a supertype of `A`.
* @param z a neutral element for the fold operation; may be added to the result
* an arbitrary number of times, and must not change the result (e.g., `Nil` for list concatenation,
- * 0 for addition, or 1 for multiplication.)
- * @param op a binary operator that must be associative
- * @return the result of applying fold operator `op` between all the elements and `z`
+ * 0 for addition, or 1 for multiplication).
+ * @param op a binary operator that must be associative.
+ * @return the result of applying the fold operator `op` between all the elements and `z`, or `z` if this $coll is empty.
*/
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1
@@ -205,6 +222,7 @@ trait GenTraversableOnce[+A] extends Any {
* op(...op(z, x_1), x_2, ..., x_n)
* }}}
* where `x,,1,,, ..., x,,n,,` are the elements of this $coll.
+ * Returns `z` if this $coll is empty.
*/
def foldLeft[B](z: B)(op: (B, A) => B): B
@@ -222,30 +240,32 @@ trait GenTraversableOnce[+A] extends Any {
* op(x_1, op(x_2, ... op(x_n, z)...))
* }}}
* where `x,,1,,, ..., x,,n,,` are the elements of this $coll.
+ * Returns `z` if this $coll is empty.
*/
def foldRight[B](z: B)(op: (A, B) => B): B
/** Aggregates the results of applying an operator to subsequent elements.
*
- * This is a more general form of `fold` and `reduce`. It has similar
- * semantics, but does not require the result to be a supertype of the
- * element type. It traverses the elements in different partitions
- * sequentially, using `seqop` to update the result, and then applies
- * `combop` to results from different partitions. The implementation of
- * this operation may operate on an arbitrary number of collection
- * partitions, so `combop` may be invoked an arbitrary number of times.
- *
- * For example, one might want to process some elements and then produce
- * a `Set`. In this case, `seqop` would process an element and append it
- * to the list, while `combop` would concatenate two lists from different
- * partitions together. The initial value `z` would be an empty set.
+ * This is a more general form of `fold` and `reduce`. It is similar to
+ * `foldLeft` in that it doesn't require the result to be a supertype of the
+ * element type. In addition, it allows parallel collections to be processed
+ * in chunks, and then combines the intermediate results.
+ *
+ * `aggregate` splits the $coll into partitions and processes each
+ * partition by sequentially applying `seqop`, starting with `z` (like
+ * `foldLeft`). Those intermediate results are then combined by using
+ * `combop` (like `fold`). The implementation of this operation may operate
+ * on an arbitrary number of collection partitions (even 1), so `combop` may
+ * be invoked an arbitrary number of times (even 0).
+ *
+ * As an example, consider summing up the integer values of a list of chars.
+ * The initial value for the sum is 0. First, `seqop` transforms each input
+ * character to an Int and adds it to the sum (of the partition). Then,
+ * `combop` just needs to sum up the intermediate results of the partitions:
* {{{
- * pc.aggregate(Set[Int]())(_ += process(_), _ ++ _)
+ * List('a', 'b', 'c').aggregate(0)({ (sum, ch) => sum + ch.toInt }, { (p1, p2) => p1 + p2 })
* }}}
*
- * Another example is calculating geometric mean from a collection of doubles
- * (one would typically require big doubles for this).
- *
* @tparam B the type of accumulated results
* @param z the initial value for the accumulated result of the partition - this
* will typically be the neutral element for the `seqop` operator (e.g.
@@ -423,13 +443,13 @@ trait GenTraversableOnce[+A] extends Any {
*/
def find(@deprecatedName('pred) p: A => Boolean): Option[A]
- /** Copies values of this $coll to an array.
+ /** Copies the elements of this $coll to an array.
* Fills the given array `xs` with values of this $coll.
* Copying will stop once either the end of the current $coll is reached,
- * or the end of the array is reached.
+ * or the end of the target array is reached.
*
* @param xs the array to fill.
- * @tparam B the type of the elements of the array.
+ * @tparam B the type of the elements of the target array.
*
* @usecase def copyToArray(xs: Array[A]): Unit
* @inheritdoc
@@ -438,14 +458,14 @@ trait GenTraversableOnce[+A] extends Any {
*/
def copyToArray[B >: A](xs: Array[B]): Unit
- /** Copies values of this $coll to an array.
+ /** Copies the elements of this $coll to an array.
* Fills the given array `xs` with values of this $coll, beginning at index `start`.
* Copying will stop once either the end of the current $coll is reached,
- * or the end of the array is reached.
+ * or the end of the target array is reached.
*
* @param xs the array to fill.
* @param start the starting index.
- * @tparam B the type of the elements of the array.
+ * @tparam B the type of the elements of the target array.
*
* @usecase def copyToArray(xs: Array[A], start: Int): Unit
* @inheritdoc
@@ -454,6 +474,22 @@ trait GenTraversableOnce[+A] extends Any {
*/
def copyToArray[B >: A](xs: Array[B], start: Int): Unit
+ /** Copies the elements of this $coll to an array.
+ * Fills the given array `xs` with at most `len` elements of
+ * this $coll, starting at position `start`.
+ * Copying will stop once either the end of the current $coll is reached,
+ * or the end of the target array is reached, or `len` elements have been copied.
+ *
+ * @param xs the array to fill.
+ * @param start the starting index.
+ * @param len the maximal number of elements to copy.
+ * @tparam B the type of the elements of the target array.
+ *
+ * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit
+ * @inheritdoc
+ *
+ * $willNotTerminateInf
+ */
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit
/** Displays all elements of this $coll in a string using start, end, and
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index ff10fb44d7..922bb2b5e0 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -890,7 +890,7 @@ trait Iterator[+A] extends TraversableOnce[A] {
* @usecase def foreach(f: A => Unit): Unit
* @inheritdoc
*/
- def foreach[U](f: A => U) { while (hasNext) f(next()) }
+ def foreach[U](f: A => U) { while (hasNext) f(next()) }
/** Tests whether a predicate holds for all values produced by this iterator.
* $mayNotTerminateInf
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
index 571d58a3f3..978f1c9075 100644
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -67,7 +67,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
}
override /*IterableLike*/
- def foreach[B](f: A => B) {
+ def foreach[U](f: A => U) {
var these = this
while (!these.isEmpty) {
f(these.head)
diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala
index b474abc12a..183279d093 100644
--- a/src/library/scala/collection/MapLike.scala
+++ b/src/library/scala/collection/MapLike.scala
@@ -171,7 +171,7 @@ self =>
def + (elem: A): Set[A] = (Set[A]() ++ this + elem).asInstanceOf[Set[A]] // !!! concrete overrides abstract problem
def - (elem: A): Set[A] = (Set[A]() ++ this - elem).asInstanceOf[Set[A]] // !!! concrete overrides abstract problem
override def size = self.size
- override def foreach[C](f: A => C) = self.keysIterator foreach f
+ override def foreach[U](f: A => U) = self.keysIterator foreach f
}
/** Creates an iterator for all keys.
@@ -203,7 +203,7 @@ self =>
protected class DefaultValuesIterable extends AbstractIterable[B] with Iterable[B] with Serializable {
def iterator = valuesIterator
override def size = self.size
- override def foreach[C](f: B => C) = self.valuesIterator foreach f
+ override def foreach[U](f: B => U) = self.valuesIterator foreach f
}
/** Creates an iterator for all values in this map.
@@ -228,7 +228,7 @@ self =>
throw new NoSuchElementException("key not found: " + key)
protected class FilteredKeys(p: A => Boolean) extends AbstractMap[A, B] with DefaultMap[A, B] {
- override def foreach[C](f: ((A, B)) => C): Unit = for (kv <- self) if (p(kv._1)) f(kv)
+ override def foreach[U](f: ((A, B)) => U): Unit = for (kv <- self) if (p(kv._1)) f(kv)
def iterator = self.iterator.filter(kv => p(kv._1))
override def contains(key: A) = p(key) && self.contains(key)
def get(key: A) = if (!p(key)) None else self.get(key)
@@ -246,7 +246,7 @@ self =>
def filterKeys(p: A => Boolean): Map[A, B] = new FilteredKeys(p)
protected class MappedValues[C](f: B => C) extends AbstractMap[A, C] with DefaultMap[A, C] {
- override def foreach[D](g: ((A, C)) => D): Unit = for ((k, v) <- self) g((k, f(v)))
+ override def foreach[U](g: ((A, C)) => U): Unit = for ((k, v) <- self) g((k, f(v)))
def iterator = for ((k, v) <- self.iterator) yield (k, f(v))
override def size = self.size
override def contains(key: A) = self.contains(key)
diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala
index a35750a35f..8145eaa204 100644
--- a/src/library/scala/collection/Traversable.scala
+++ b/src/library/scala/collection/Traversable.scala
@@ -38,7 +38,7 @@ trait Traversable[+A] extends TraversableLike[A, Traversable[A]]
override def remove(p: A => Boolean): Traversable[A]
override def partition(p: A => Boolean): (Traversable[A], Traversable[A])
override def groupBy[K](f: A => K): Map[K, Traversable[A]]
- override def foreach[U](f: A => U): Unit
+ override def foreach[U](f: A => U): Unit
override def forall(p: A => Boolean): Boolean
override def exists(p: A => Boolean): Boolean
override def count(p: A => Boolean): Int
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala
index a0b1430d17..32718ddf03 100644
--- a/src/library/scala/collection/TraversableLike.scala
+++ b/src/library/scala/collection/TraversableLike.scala
@@ -340,14 +340,6 @@ trait TraversableLike[+A, +Repr] extends Any
b.result
}
- /** Tests whether a predicate holds for all elements of this $coll.
- *
- * $mayNotTerminateInf
- *
- * @param p the predicate used to test elements.
- * @return `true` if this $coll is empty, otherwise `true` if the given predicate `p`
- * holds for all elements of this $coll, otherwise `false`.
- */
def forall(p: A => Boolean): Boolean = {
var result = true
breakable {
@@ -374,15 +366,6 @@ trait TraversableLike[+A, +Repr] extends Any
result
}
- /** Finds the first element of the $coll satisfying a predicate, if any.
- *
- * $mayNotTerminateInf
- * $orderDependent
- *
- * @param p the predicate used to test elements.
- * @return an option value containing the first element in the $coll
- * that satisfies `p`, or `None` if none exists.
- */
def find(p: A => Boolean): Option[A] = {
var result: Option[A] = None
breakable {
@@ -594,23 +577,6 @@ trait TraversableLike[+A, +Repr] extends Any
*/
def inits: Iterator[Repr] = iterateUntilEmpty(_.init)
- /** Copies elements of this $coll to an array.
- * Fills the given array `xs` with at most `len` elements of
- * this $coll, starting at position `start`.
- * Copying will stop once either the end of the current $coll is reached,
- * or the end of the array is reached, or `len` elements have been copied.
- *
- * @param xs the array to fill.
- * @param start the starting index.
- * @param len the maximal number of elements to copy.
- * @tparam B the type of the elements of the array.
- *
- *
- * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit
- * @inheritdoc
- *
- * $willNotTerminateInf
- */
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
var i = start
val end = (start + len) min xs.length
@@ -625,7 +591,7 @@ trait TraversableLike[+A, +Repr] extends Any
@deprecatedOverriding("Enforce contract of toTraversable that if it is Traversable it returns itself.", "2.11.0")
def toTraversable: Traversable[A] = thisCollection
-
+
def toIterator: Iterator[A] = toStream.iterator
def toStream: Stream[A] = toBuffer.toStream
// Override to provide size hint.
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index c5b0d0f085..910c59b179 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -61,7 +61,8 @@ import scala.reflect.ClassTag
trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
self =>
- /** Self-documenting abstract methods. */
+ /* Self-documenting abstract methods. */
+
def foreach[U](f: A => U): Unit
def isEmpty: Boolean
def hasDefiniteSize: Boolean
@@ -334,10 +335,10 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
* {{{
* scala> val a = List(1,2,3,4)
* a: List[Int] = List(1, 2, 3, 4)
- *
+ *
* scala> val b = new StringBuilder()
- * b: StringBuilder =
- *
+ * b: StringBuilder =
+ *
* scala> a.addString(b , "List(" , ", " , ")")
* res5: StringBuilder = List(1, 2, 3, 4)
* }}}
@@ -376,7 +377,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
* {{{
* scala> val a = List(1,2,3,4)
* a: List[Int] = List(1, 2, 3, 4)
- *
+ *
* scala> val b = new StringBuilder()
* b: StringBuilder =
*
@@ -399,7 +400,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
* {{{
* scala> val a = List(1,2,3,4)
* a: List[Int] = List(1, 2, 3, 4)
- *
+ *
* scala> val b = new StringBuilder()
* b: StringBuilder =
*
diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala
index 4399dbc289..fa470ea238 100644
--- a/src/library/scala/collection/TraversableProxyLike.scala
+++ b/src/library/scala/collection/TraversableProxyLike.scala
@@ -28,7 +28,7 @@ import scala.reflect.ClassTag
trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversable[A]] extends TraversableLike[A, Repr] with Proxy {
def self: Repr
- override def foreach[B](f: A => B): Unit = self.foreach(f)
+ override def foreach[U](f: A => U): Unit = self.foreach(f)
override def isEmpty: Boolean = self.isEmpty
override def nonEmpty: Boolean = self.nonEmpty
override def size: Int = self.size
diff --git a/src/library/scala/collection/generic/TraversableForwarder.scala b/src/library/scala/collection/generic/TraversableForwarder.scala
index 1d7974f7a4..359ea402b6 100644
--- a/src/library/scala/collection/generic/TraversableForwarder.scala
+++ b/src/library/scala/collection/generic/TraversableForwarder.scala
@@ -32,7 +32,7 @@ trait TraversableForwarder[+A] extends Traversable[A] {
/** The traversable object to which calls are forwarded. */
protected def underlying: Traversable[A]
- override def foreach[B](f: A => B): Unit = underlying foreach f
+ override def foreach[U](f: A => U): Unit = underlying foreach f
override def isEmpty: Boolean = underlying.isEmpty
override def nonEmpty: Boolean = underlying.nonEmpty
override def size: Int = underlying.size
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala
index 3b3e65ea61..92d915fe8b 100644
--- a/src/library/scala/collection/immutable/HashMap.scala
+++ b/src/library/scala/collection/immutable/HashMap.scala
@@ -48,7 +48,7 @@ class HashMap[A, +B] extends AbstractMap[A, B]
def iterator: Iterator[(A,B)] = Iterator.empty
- override def foreach[U](f: ((A, B)) => U): Unit = { }
+ override def foreach[U](f: ((A, B)) => U): Unit = ()
def get(key: A): Option[B] =
get0(key, computeHash(key), 0)
@@ -422,7 +422,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
final override def getElem(cc: AnyRef): (A, B) = cc.asInstanceOf[HashMap1[A, B]].ensurePair
}
- override def foreach[U](f: ((A, B)) => U): Unit = {
+ override def foreach[U](f: ((A, B)) => U): Unit = {
var i = 0
while (i < elems.length) {
elems(i).foreach(f)
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala
index 603d97c3ad..07758bf5a2 100644
--- a/src/library/scala/collection/immutable/HashSet.scala
+++ b/src/library/scala/collection/immutable/HashSet.scala
@@ -53,7 +53,7 @@ class HashSet[A] extends AbstractSet[A]
def iterator: Iterator[A] = Iterator.empty
- override def foreach[U](f: A => U): Unit = { }
+ override def foreach[U](f: A => U): Unit = ()
def contains(e: A): Boolean = get0(e, computeHash(e), 0)
@@ -215,7 +215,7 @@ object HashSet extends ImmutableSetFactory[HashSet] {
private object EmptyHashSet extends HashSet[Any] { }
private[collection] def emptyInstance: HashSet[Any] = EmptyHashSet
-
+
// utility method to create a HashTrieSet from two leaf HashSets (HashSet1 or HashSetCollision1) with non-colliding hash code)
private def makeHashTrieSet[A](hash0:Int, elem0:HashSet[A], hash1:Int, elem1:HashSet[A], level:Int) : HashTrieSet[A] = {
val index0 = (hash0 >>> level) & 0x1f
@@ -966,7 +966,7 @@ object HashSet extends ImmutableSetFactory[HashSet] {
final override def getElem(cc: AnyRef): A = cc.asInstanceOf[HashSet1[A]].key
}
- override def foreach[U](f: A => U): Unit = {
+ override def foreach[U](f: A => U): Unit = {
var i = 0
while (i < elems.length) {
elems(i).foreach(f)
diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala
index cb6196e130..c6bf6a77e8 100644
--- a/src/library/scala/collection/immutable/IntMap.scala
+++ b/src/library/scala/collection/immutable/IntMap.scala
@@ -184,7 +184,7 @@ sealed abstract class IntMap[+T] extends AbstractMap[Int, T]
/**
* Loops over the key, value pairs of the map in unsigned order of the keys.
*/
- override final def foreach[U](f: ((Int, T)) => U): Unit = this match {
+ override final def foreach[U](f: ((Int, T)) => U): Unit = this match {
case IntMap.Bin(_, _, left, right) => { left.foreach(f); right.foreach(f) }
case IntMap.Tip(key, value) => f((key, value))
case IntMap.Nil =>
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala
index 66150c1a13..3ad567375c 100644
--- a/src/library/scala/collection/immutable/List.scala
+++ b/src/library/scala/collection/immutable/List.scala
@@ -25,6 +25,19 @@ import java.io.{ObjectOutputStream, ObjectInputStream}
* This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access
* pattern, for example, random access or FIFO, consider using a collection more suited to this than `List`.
*
+ * ==Performance==
+ * '''Time:''' `List` has `O(1)` prepend and head/tail access. Most other operations are `O(n)` on the number of elements in the list.
+ * This includes the index-based lookup of elements, `length`, `append` and `reverse`.
+ *
+ * '''Space:''' `List` implements '''structural sharing''' of the tail list. This means that many operations are either
+ * zero- or constant-memory cost.
+ * {{{
+ * val mainList = List(3, 2, 1)
+ * val with4 = 4 :: mainList // re-uses mainList, costs one :: instance
+ * val with42 = 42 :: mainList // also re-uses mainList, cost one :: instance
+ * val shorter = mainList.tail // costs nothing as it uses the same 2::1::Nil instances as mainList
+ * }}}
+ *
* @example {{{
* // Make a list via the companion object factory
* val days = List("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
@@ -41,19 +54,6 @@ import java.io.{ObjectOutputStream, ObjectInputStream}
* }
* }}}
*
- * ==Performance==
- * '''Time:''' `List` has `O(1)` prepend and head/tail access. Most other operations are `O(n)` on the number of elements in the list.
- * This includes the index-based lookup of elements, `length`, `append` and `reverse`.
- *
- * '''Space:''' `List` implements '''structural sharing''' of the tail list. This means that many operations are either
- * zero- or constant-memory cost.
- * {{{
- * val mainList = List(3, 2, 1)
- * val with4 = 4 :: mainList // re-uses mainList, costs one :: instance
- * val with42 = 42 :: mainList // also re-uses mainList, cost one :: instance
- * val shorter = mainList.tail // costs nothing as it uses the same 2::1::Nil instances as mainList
- * }}}
- *
* @note The functional list is characterized by persistence and structural sharing, thus offering considerable
* performance and space consumption benefits in some scenarios if used correctly.
* However, note that objects having multiple references into the same functional list (that is,
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala
index 868c0c0f47..173d912fe5 100644
--- a/src/library/scala/collection/immutable/LongMap.scala
+++ b/src/library/scala/collection/immutable/LongMap.scala
@@ -176,7 +176,7 @@ extends AbstractMap[Long, T]
/**
* Loops over the key, value pairs of the map in unsigned order of the keys.
*/
- override final def foreach[U](f: ((Long, T)) => U): Unit = this match {
+ override final def foreach[U](f: ((Long, T)) => U): Unit = this match {
case LongMap.Bin(_, _, left, right) => { left.foreach(f); right.foreach(f) }
case LongMap.Tip(key, value) => f((key, value))
case LongMap.Nil =>
diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala
index 63ddcb18cf..6f135cd35f 100644
--- a/src/library/scala/collection/immutable/Map.scala
+++ b/src/library/scala/collection/immutable/Map.scala
@@ -116,7 +116,7 @@ object Map extends ImmutableMapFactory[Map] {
def + [B1 >: B](kv: (A, B1)): Map[A, B1] = updated(kv._1, kv._2)
def - (key: A): Map[A, B] =
if (key == key1) Map.empty else this
- override def foreach[U](f: ((A, B)) => U): Unit = {
+ override def foreach[U](f: ((A, B)) => U): Unit = {
f((key1, value1))
}
}
@@ -142,7 +142,7 @@ object Map extends ImmutableMapFactory[Map] {
if (key == key1) new Map1(key2, value2)
else if (key == key2) new Map1(key1, value1)
else this
- override def foreach[U](f: ((A, B)) => U): Unit = {
+ override def foreach[U](f: ((A, B)) => U): Unit = {
f((key1, value1)); f((key2, value2))
}
}
@@ -172,7 +172,7 @@ object Map extends ImmutableMapFactory[Map] {
else if (key == key2) new Map2(key1, value1, key3, value3)
else if (key == key3) new Map2(key1, value1, key2, value2)
else this
- override def foreach[U](f: ((A, B)) => U): Unit = {
+ override def foreach[U](f: ((A, B)) => U): Unit = {
f((key1, value1)); f((key2, value2)); f((key3, value3))
}
}
@@ -206,7 +206,7 @@ object Map extends ImmutableMapFactory[Map] {
else if (key == key3) new Map3(key1, value1, key2, value2, key4, value4)
else if (key == key4) new Map3(key1, value1, key2, value2, key3, value3)
else this
- override def foreach[U](f: ((A, B)) => U): Unit = {
+ override def foreach[U](f: ((A, B)) => U): Unit = {
f((key1, value1)); f((key2, value2)); f((key3, value3)); f((key4, value4))
}
}
diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala
index c8d0b00327..d3dc65f834 100644
--- a/src/library/scala/collection/immutable/PagedSeq.scala
+++ b/src/library/scala/collection/immutable/PagedSeq.scala
@@ -23,6 +23,7 @@ import scala.reflect.ClassTag
* `fromIterator` and `fromIterable` provide generalised instances of `PagedSeq`
* @since 2.7
*/
+@deprecated("This object will be moved to the scala-parser-combinators module", "2.11.8")
object PagedSeq {
final val UndeterminedEnd = Int.MaxValue
@@ -126,7 +127,7 @@ import PagedSeq._
* @define mayNotTerminateInf
* @define willNotTerminateInf
*/
-@deprecatedInheritance("The implementation details of paged sequences make inheriting from them unwise.", "2.11.0")
+@deprecated("This class will be moved to the scala-parser-combinators module", "2.11.8")
class PagedSeq[T: ClassTag] protected(
more: (Array[T], Int, Int) => Int,
first1: Page[T],
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 5989517532..aa98b810d4 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -176,9 +176,9 @@ import scala.language.implicitConversions
* loop(1, 1)
* }
* }}}
- *
+ *
* Note that `mkString` forces evaluation of a `Stream`, but `addString` does
- * not. In both cases, a `Stream` that is or ends in a cycle
+ * not. In both cases, a `Stream` that is or ends in a cycle
* (e.g. `lazy val s: Stream[Int] = 0 #:: s`) will convert additional trips
* through the cycle to `...`. Additionally, `addString` will display an
* un-memoized tail as `?`.
@@ -528,7 +528,7 @@ self =>
* unless the `f` throws an exception.
*/
@tailrec
- override final def foreach[B](f: A => B) {
+ override final def foreach[U](f: A => U) {
if (!this.isEmpty) {
f(head)
tail.foreach(f)
diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala
index 662075cd93..b845b76026 100644
--- a/src/library/scala/collection/immutable/TreeMap.scala
+++ b/src/library/scala/collection/immutable/TreeMap.scala
@@ -200,5 +200,5 @@ class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering: Orderi
override def contains(key: A): Boolean = RB.contains(tree, key)
override def isDefinedAt(key: A): Boolean = RB.contains(tree, key)
- override def foreach[U](f : ((A,B)) => U) = RB.foreach(tree, f)
+ override def foreach[U](f : ((A,B)) => U) = RB.foreach(tree, f)
}
diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala
index 7378211db0..2800030d67 100644
--- a/src/library/scala/collection/immutable/TreeSet.scala
+++ b/src/library/scala/collection/immutable/TreeSet.scala
@@ -151,7 +151,7 @@ class TreeSet[A] private (tree: RB.Tree[A, Unit])(implicit val ordering: Orderin
def iterator: Iterator[A] = RB.keysIterator(tree)
override def keysIteratorFrom(start: A): Iterator[A] = RB.keysIterator(tree, Some(start))
- override def foreach[U](f: A => U) = RB.foreachKey(tree, f)
+ override def foreach[U](f: A => U) = RB.foreachKey(tree, f)
override def rangeImpl(from: Option[A], until: Option[A]): TreeSet[A] = newSet(RB.rangeImpl(tree, from, until))
override def range(from: A, until: A): TreeSet[A] = newSet(RB.range(tree, from, until))
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala
index 8bb581d44c..cd2d3f843b 100644
--- a/src/library/scala/collection/immutable/Vector.scala
+++ b/src/library/scala/collection/immutable/Vector.scala
@@ -951,8 +951,6 @@ private[immutable] trait VectorPointer[T] {
// STUFF BELOW USED BY APPEND / UPDATE
private[immutable] final def copyOf(a: Array[AnyRef]) = {
- //println("copy")
- if (a eq null) println ("NULL")
val b = new Array[AnyRef](a.length)
Platform.arraycopy(a, 0, b, 0, a.length)
b
diff --git a/src/library/scala/collection/mutable/AnyRefMap.scala b/src/library/scala/collection/mutable/AnyRefMap.scala
index 46991ac101..af7600ad3d 100644
--- a/src/library/scala/collection/mutable/AnyRefMap.scala
+++ b/src/library/scala/collection/mutable/AnyRefMap.scala
@@ -5,23 +5,23 @@ package mutable
import generic.CanBuildFrom
/** This class implements mutable maps with `AnyRef` keys based on a hash table with open addressing.
- *
- * Basic map operations on single entries, including `contains` and `get`,
+ *
+ * Basic map operations on single entries, including `contains` and `get`,
* are typically significantly faster with `AnyRefMap` than [[HashMap]].
* Note that numbers and characters are not handled specially in AnyRefMap;
* only plain `equals` and `hashCode` are used in comparisons.
- *
+ *
* Methods that traverse or regenerate the map, including `foreach` and `map`,
* are not in general faster than with `HashMap`. The methods `foreachKey`,
* `foreachValue`, `mapValuesNow`, and `transformValues` are, however, faster
* than alternative ways to achieve the same functionality.
- *
+ *
* Maps with open addressing may become less efficient at lookup after
* repeated addition/removal of elements. Although `AnyRefMap` makes a
* decent attempt to remain efficient regardless, calling `repack`
* on a map that will no longer have elements removed but will be
* used heavily may save both time and storage space.
- *
+ *
* This map is not intended to contain more than 2^29^ entries (approximately
* 500 million). The maximum capacity is 2^30^, but performance will degrade
* rapidly as 2^30^ is approached.
@@ -36,50 +36,50 @@ extends AbstractMap[K, V]
{
import AnyRefMap._
def this() = this(AnyRefMap.exceptionDefault, 16, true)
-
+
/** Creates a new `AnyRefMap` that returns default values according to a supplied key-value mapping. */
def this(defaultEntry: K => V) = this(defaultEntry, 16, true)
/** Creates a new `AnyRefMap` with an initial buffer of specified size.
- *
+ *
* An `AnyRefMap` can typically contain half as many elements as its buffer size
* before it requires resizing.
*/
def this(initialBufferSize: Int) = this(AnyRefMap.exceptionDefault, initialBufferSize, true)
-
+
/** Creates a new `AnyRefMap` with specified default values and initial buffer size. */
def this(defaultEntry: K => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true)
-
+
private[this] var mask = 0
private[this] var _size = 0
private[this] var _vacant = 0
private[this] var _hashes: Array[Int] = null
private[this] var _keys: Array[AnyRef] = null
private[this] var _values: Array[AnyRef] = null
-
+
if (initBlank) defaultInitialize(initialBufferSize)
-
+
private[this] def defaultInitialize(n: Int) {
- mask =
+ mask =
if (n<0) 0x7
else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7
_hashes = new Array[Int](mask+1)
_keys = new Array[AnyRef](mask+1)
_values = new Array[AnyRef](mask+1)
}
-
+
private[collection] def initializeTo(
m: Int, sz: Int, vc: Int, hz: Array[Int], kz: Array[AnyRef], vz: Array[AnyRef]
) {
mask = m; _size = sz; _vacant = vc; _hashes = hz; _keys = kz; _values = vz
}
-
+
override def size: Int = _size
override def empty: AnyRefMap[K,V] = new AnyRefMap(defaultEntry)
-
- private def imbalanced: Boolean =
+
+ private def imbalanced: Boolean =
(_size + _vacant) > 0.5*mask || _vacant > _size
-
+
private def hashOf(key: K): Int = {
if (key eq null) 0x41081989
else {
@@ -90,7 +90,7 @@ extends AbstractMap[K, V]
if (j==0) 0x41081989 else j & 0x7FFFFFFF
}
}
-
+
private def seekEntry(h: Int, k: AnyRef): Int = {
var e = h & mask
var x = 0
@@ -102,7 +102,7 @@ extends AbstractMap[K, V]
}
e | MissingBit
}
-
+
private def seekEntryOrOpen(h: Int, k: AnyRef): Int = {
var e = h & mask
var x = 0
@@ -116,19 +116,19 @@ extends AbstractMap[K, V]
}
if (o >= 0) o | MissVacant else e | MissingBit
}
-
+
override def contains(key: K): Boolean = seekEntry(hashOf(key), key) >= 0
-
+
override def get(key: K): Option[V] = {
val i = seekEntry(hashOf(key), key)
if (i < 0) None else Some(_values(i).asInstanceOf[V])
}
-
+
override def getOrElse[V1 >: V](key: K, default: => V1): V1 = {
val i = seekEntry(hashOf(key), key)
if (i < 0) default else _values(i).asInstanceOf[V]
}
-
+
override def getOrElseUpdate(key: K, defaultValue: => V): V = {
val h = hashOf(key)
var i = seekEntryOrOpen(h, key)
@@ -156,10 +156,10 @@ extends AbstractMap[K, V]
}
else _values(i).asInstanceOf[V]
}
-
+
/** Retrieves the value associated with a key, or the default for that type if none exists
* (null for AnyRef, 0 for floats and integers).
- *
+ *
* Note: this is the fastest way to retrieve a value that may or
* may not exist, if the default null/zero is acceptable. For key/value
* pairs that do exist, `apply` (i.e. `map(key)`) is equally fast.
@@ -168,22 +168,22 @@ extends AbstractMap[K, V]
val i = seekEntry(hashOf(key), key)
(if (i < 0) null else _values(i)).asInstanceOf[V]
}
-
- /** Retrieves the value associated with a key.
+
+ /** Retrieves the value associated with a key.
* If the key does not exist in the map, the `defaultEntry` for that key
- * will be returned instead; an exception will be thrown if no
+ * will be returned instead; an exception will be thrown if no
* `defaultEntry` was supplied.
*/
override def apply(key: K): V = {
val i = seekEntry(hashOf(key), key)
if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V]
}
-
+
/** Defers to defaultEntry to find a default value for the key. Throws an
* exception if no other default behavior was specified.
*/
override def default(key: K) = defaultEntry(key)
-
+
private def repack(newMask: Int) {
val oh = _hashes
val ok = _keys
@@ -207,9 +207,9 @@ extends AbstractMap[K, V]
i += 1
}
}
-
+
/** Repacks the contents of this `AnyRefMap` for maximum efficiency of lookup.
- *
+ *
* For maps that undergo a complex creation process with both addition and
* removal of keys, and then are used heavily with no further removal of
* elements, calling `repack` after the end of the creation can result in
@@ -222,7 +222,7 @@ extends AbstractMap[K, V]
while (m > 8 && 8*_size < m) m = m >>> 1
repack(m)
}
-
+
override def put(key: K, value: V): Option[V] = {
val h = hashOf(key)
val k = key
@@ -245,9 +245,9 @@ extends AbstractMap[K, V]
ans
}
}
-
+
/** Updates the map to include a new key-value pair.
- *
+ *
* This is the fastest way to add an entry to an `AnyRefMap`.
*/
override def update(key: K, value: V): Unit = {
@@ -269,12 +269,12 @@ extends AbstractMap[K, V]
_values(i) = value.asInstanceOf[AnyRef]
}
}
-
+
/** Adds a new key/value pair to this map and returns the map. */
def +=(key: K, value: V): this.type = { update(key, value); this }
def +=(kv: (K, V)): this.type = { update(kv._1, kv._2); this }
-
+
def -=(key: K): this.type = {
val i = seekEntry(hashOf(key), key)
if (i >= 0) {
@@ -286,14 +286,14 @@ extends AbstractMap[K, V]
}
this
}
-
+
def iterator: Iterator[(K, V)] = new Iterator[(K, V)] {
private[this] val hz = _hashes
private[this] val kz = _keys
private[this] val vz = _values
-
+
private[this] var index = 0
-
+
def hasNext: Boolean = index<hz.length && {
var h = hz(index)
while (h+h == 0) {
@@ -303,7 +303,7 @@ extends AbstractMap[K, V]
}
true
}
-
+
def next: (K, V) = {
if (hasNext) {
val ans = (kz(index).asInstanceOf[K], vz(index).asInstanceOf[V])
@@ -313,8 +313,8 @@ extends AbstractMap[K, V]
else throw new NoSuchElementException("next")
}
}
-
- override def foreach[A](f: ((K,V)) => A) {
+
+ override def foreach[U](f: ((K,V)) => U) {
var i = 0
var e = _size
while (e > 0) {
@@ -327,7 +327,7 @@ extends AbstractMap[K, V]
else return
}
}
-
+
override def clone(): AnyRefMap[K, V] = {
val hz = java.util.Arrays.copyOf(_hashes, _hashes.length)
val kz = java.util.Arrays.copyOf(_keys, _keys.length)
@@ -336,25 +336,25 @@ extends AbstractMap[K, V]
arm.initializeTo(mask, _size, _vacant, hz, kz, vz)
arm
}
-
+
override def +[V1 >: V](kv: (K, V1)): AnyRefMap[K, V1] = {
val arm = clone().asInstanceOf[AnyRefMap[K, V1]]
arm += kv
arm
}
-
+
override def ++[V1 >: V](xs: GenTraversableOnce[(K, V1)]): AnyRefMap[K, V1] = {
val arm = clone().asInstanceOf[AnyRefMap[K, V1]]
xs.foreach(kv => arm += kv)
arm
}
-
+
override def updated[V1 >: V](key: K, value: V1): AnyRefMap[K, V1] = {
val arm = clone().asInstanceOf[AnyRefMap[K, V1]]
arm += (key, value)
arm
}
-
+
private[this] def foreachElement[A,B](elems: Array[AnyRef], f: A => B) {
var i,j = 0
while (i < _hashes.length & j < _size) {
@@ -366,13 +366,13 @@ extends AbstractMap[K, V]
i += 1
}
}
-
+
/** Applies a function to all keys of this map. */
def foreachKey[A](f: K => A) { foreachElement[K,A](_keys, f) }
/** Applies a function to all values of this map. */
def foreachValue[A](f: V => A) { foreachElement[V,A](_values, f) }
-
+
/** Creates a new `AnyRefMap` with different values.
* Unlike `mapValues`, this method generates a new
* collection immediately.
@@ -394,8 +394,8 @@ extends AbstractMap[K, V]
arm.initializeTo(mask, _size, _vacant, hz, kz, vz)
arm
}
-
- /** Applies a transformation function to all values stored in this map.
+
+ /** Applies a transformation function to all values stored in this map.
* Note: the default, if any, is not transformed.
*/
def transformValues(f: V => V): this.type = {
@@ -418,15 +418,15 @@ object AnyRefMap {
private final val MissingBit = 0x80000000
private final val VacantBit = 0x40000000
private final val MissVacant = 0xC0000000
-
+
private val exceptionDefault = (k: Any) => throw new NoSuchElementException(if (k == null) "(null)" else k.toString)
-
+
implicit def canBuildFrom[K <: AnyRef, V, J <: AnyRef, U]: CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] =
new CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] {
def apply(from: AnyRefMap[K,V]): AnyRefMapBuilder[J, U] = apply()
def apply(): AnyRefMapBuilder[J, U] = new AnyRefMapBuilder[J, U]
}
-
+
final class AnyRefMapBuilder[K <: AnyRef, V] extends Builder[(K, V), AnyRefMap[K, V]] {
private[collection] var elems: AnyRefMap[K, V] = new AnyRefMap[K, V]
def +=(entry: (K, V)): this.type = {
@@ -445,14 +445,14 @@ object AnyRefMap {
if (arm.size < (sz>>3)) arm.repack()
arm
}
-
+
/** Creates a new empty `AnyRefMap`. */
def empty[K <: AnyRef, V]: AnyRefMap[K, V] = new AnyRefMap[K, V]
-
+
/** Creates a new empty `AnyRefMap` with the supplied default */
def withDefault[K <: AnyRef, V](default: K => V): AnyRefMap[K, V] = new AnyRefMap[K, V](default)
-
- /** Creates a new `AnyRefMap` from arrays of keys and values.
+
+ /** Creates a new `AnyRefMap` from arrays of keys and values.
* Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`.
*/
def fromZip[K <: AnyRef, V](keys: Array[K], values: Array[V]): AnyRefMap[K, V] = {
@@ -463,8 +463,8 @@ object AnyRefMap {
if (arm.size < (sz>>3)) arm.repack()
arm
}
-
- /** Creates a new `AnyRefMap` from keys and values.
+
+ /** Creates a new `AnyRefMap` from keys and values.
* Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`.
*/
def fromZip[K <: AnyRef, V](keys: Iterable[K], values: Iterable[V]): AnyRefMap[K, V] = {
diff --git a/src/library/scala/collection/mutable/ArraySeq.scala b/src/library/scala/collection/mutable/ArraySeq.scala
index 5a50f4fb27..1e82096baf 100644
--- a/src/library/scala/collection/mutable/ArraySeq.scala
+++ b/src/library/scala/collection/mutable/ArraySeq.scala
@@ -68,7 +68,7 @@ extends AbstractSeq[A]
array(idx) = elem.asInstanceOf[AnyRef]
}
- override def foreach[U](f: A => U) {
+ override def foreach[U](f: A => U) {
var i = 0
while (i < length) {
f(array(i).asInstanceOf[A])
diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala
index fec2da8839..8ff128c026 100644
--- a/src/library/scala/collection/mutable/ArrayStack.scala
+++ b/src/library/scala/collection/mutable/ArrayStack.scala
@@ -233,7 +233,7 @@ extends AbstractSeq[T]
}
}
- override def foreach[U](f: T => U) {
+ override def foreach[U](f: T => U) {
var currentIndex = index
while (currentIndex > 0) {
currentIndex -= 1
diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala
index 6fca75ffea..eab4202353 100644
--- a/src/library/scala/collection/mutable/HashMap.scala
+++ b/src/library/scala/collection/mutable/HashMap.scala
@@ -96,16 +96,16 @@ extends AbstractMap[A, B]
def iterator = entriesIterator map (e => ((e.key, e.value)))
- override def foreach[C](f: ((A, B)) => C): Unit = foreachEntry(e => f((e.key, e.value)))
+ override def foreach[U](f: ((A, B)) => U): Unit = foreachEntry(e => f((e.key, e.value)))
/* Override to avoid tuple allocation in foreach */
override def keySet: scala.collection.Set[A] = new DefaultKeySet {
- override def foreach[C](f: A => C) = foreachEntry(e => f(e.key))
+ override def foreach[U](f: A => U) = foreachEntry(e => f(e.key))
}
/* Override to avoid tuple allocation in foreach */
override def values: scala.collection.Iterable[B] = new DefaultValuesIterable {
- override def foreach[C](f: B => C) = foreachEntry(e => f(e.value))
+ override def foreach[U](f: B => U) = foreachEntry(e => f(e.value))
}
/* Override to avoid tuple allocation */
diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala
index 886fee5a59..3a16e4efa5 100644
--- a/src/library/scala/collection/mutable/HashSet.scala
+++ b/src/library/scala/collection/mutable/HashSet.scala
@@ -70,7 +70,7 @@ extends AbstractSet[A]
override def iterator: Iterator[A] = super[FlatHashTable].iterator
- override def foreach[U](f: A => U) {
+ override def foreach[U](f: A => U) {
var i = 0
val len = table.length
while (i < len) {
diff --git a/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala b/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala
index 730b22227d..d7eec70b15 100644
--- a/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala
+++ b/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala
@@ -32,7 +32,7 @@ extends AbstractSet[A]
def contains(elem: A): Boolean = set.contains(elem)
- override def foreach[U](f: A => U): Unit = set.foreach(f)
+ override def foreach[U](f: A => U): Unit = set.foreach(f)
override def exists(p: A => Boolean): Boolean = set.exists(p)
diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala
index a9d385bc5b..d0748b8a9f 100644
--- a/src/library/scala/collection/mutable/LinkedListLike.scala
+++ b/src/library/scala/collection/mutable/LinkedListLike.scala
@@ -172,7 +172,7 @@ trait LinkedListLike[A, This <: Seq[A] with LinkedListLike[A, This]] extends Seq
}
}
- override def foreach[B](f: A => B) {
+ override def foreach[U](f: A => U) {
var these = this
while (these.nonEmpty) {
f(these.elem)
diff --git a/src/library/scala/collection/mutable/LongMap.scala b/src/library/scala/collection/mutable/LongMap.scala
index 1eb12d817c..f39a6ba634 100644
--- a/src/library/scala/collection/mutable/LongMap.scala
+++ b/src/library/scala/collection/mutable/LongMap.scala
@@ -5,20 +5,20 @@ package mutable
import generic.CanBuildFrom
/** This class implements mutable maps with `Long` keys based on a hash table with open addressing.
- *
- * Basic map operations on single entries, including `contains` and `get`,
+ *
+ * Basic map operations on single entries, including `contains` and `get`,
* are typically substantially faster with `LongMap` than [[HashMap]]. Methods
* that act on the whole map, including `foreach` and `map` are not in
* general expected to be faster than with a generic map, save for those
* that take particular advantage of the internal structure of the map:
* `foreachKey`, `foreachValue`, `mapValuesNow`, and `transformValues`.
- *
+ *
* Maps with open addressing may become less efficient at lookup after
* repeated addition/removal of elements. Although `LongMap` makes a
* decent attempt to remain efficient regardless, calling `repack`
* on a map that will no longer have elements removed but will be
* used heavily may save both time and storage space.
- *
+ *
* This map is not intended to contain more than 2^29 entries (approximately
* 500 million). The maximum capacity is 2^30, but performance will degrade
* rapidly as 2^30 is approached.
@@ -33,20 +33,20 @@ extends AbstractMap[Long, V]
import LongMap._
def this() = this(LongMap.exceptionDefault, 16, true)
-
+
/** Creates a new `LongMap` that returns default values according to a supplied key-value mapping. */
def this(defaultEntry: Long => V) = this(defaultEntry, 16, true)
-
+
/** Creates a new `LongMap` with an initial buffer of specified size.
- *
+ *
* A LongMap can typically contain half as many elements as its buffer size
* before it requires resizing.
*/
def this(initialBufferSize: Int) = this(LongMap.exceptionDefault, initialBufferSize, true)
-
+
/** Creates a new `LongMap` with specified default values and initial buffer size. */
def this(defaultEntry: Long => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true)
-
+
private[this] var mask = 0
private[this] var extraKeys: Int = 0
private[this] var zeroValue: AnyRef = null
@@ -55,43 +55,43 @@ extends AbstractMap[Long, V]
private[this] var _vacant = 0
private[this] var _keys: Array[Long] = null
private[this] var _values: Array[AnyRef] = null
-
+
if (initBlank) defaultInitialize(initialBufferSize)
-
+
private[this] def defaultInitialize(n: Int) = {
- mask =
+ mask =
if (n<0) 0x7
else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7
_keys = new Array[Long](mask+1)
_values = new Array[AnyRef](mask+1)
}
-
+
private[collection] def initializeTo(
m: Int, ek: Int, zv: AnyRef, mv: AnyRef, sz: Int, vc: Int, kz: Array[Long], vz: Array[AnyRef]
) {
mask = m; extraKeys = ek; zeroValue = zv; minValue = mv; _size = sz; _vacant = vc; _keys = kz; _values = vz
}
-
+
override def size: Int = _size + (extraKeys+1)/2
override def empty: LongMap[V] = new LongMap()
-
- private def imbalanced: Boolean =
+
+ private def imbalanced: Boolean =
(_size + _vacant) > 0.5*mask || _vacant > _size
-
+
private def toIndex(k: Long): Int = {
// Part of the MurmurHash3 32 bit finalizer
val h = ((k ^ (k >>> 32)) & 0xFFFFFFFFL).toInt
val x = (h ^ (h >>> 16)) * 0x85EBCA6B
(x ^ (x >>> 13)) & mask
}
-
+
private def seekEmpty(k: Long): Int = {
var e = toIndex(k)
var x = 0
while (_keys(e) != 0) { x += 1; e = (e + 2*(x+1)*x - 3) & mask }
e
}
-
+
private def seekEntry(k: Long): Int = {
var e = toIndex(k)
var x = 0
@@ -99,7 +99,7 @@ extends AbstractMap[Long, V]
while ({ q = _keys(e); if (q==k) return e; q != 0}) { x += 1; e = (e + 2*(x+1)*x - 3) & mask }
e | MissingBit
}
-
+
private def seekEntryOrOpen(k: Long): Int = {
var e = toIndex(k)
var x = 0
@@ -116,12 +116,12 @@ extends AbstractMap[Long, V]
}
o
}
-
+
override def contains(key: Long): Boolean = {
if (key == -key) (((key>>>63).toInt+1) & extraKeys) != 0
else seekEntry(key) >= 0
}
-
+
override def get(key: Long): Option[V] = {
if (key == -key) {
if ((((key>>>63).toInt+1) & extraKeys) == 0) None
@@ -133,7 +133,7 @@ extends AbstractMap[Long, V]
if (i < 0) None else Some(_values(i).asInstanceOf[V])
}
}
-
+
override def getOrElse[V1 >: V](key: Long, default: => V1): V1 = {
if (key == -key) {
if ((((key>>>63).toInt+1) & extraKeys) == 0) default
@@ -145,7 +145,7 @@ extends AbstractMap[Long, V]
if (i < 0) default else _values(i).asInstanceOf[V1]
}
}
-
+
override def getOrElseUpdate(key: Long, defaultValue: => V): V = {
if (key == -key) {
val kbits = (key>>>63).toInt + 1
@@ -185,10 +185,10 @@ extends AbstractMap[Long, V]
else _values(i).asInstanceOf[V]
}
}
-
+
/** Retrieves the value associated with a key, or the default for that type if none exists
* (null for AnyRef, 0 for floats and integers).
- *
+ *
* Note: this is the fastest way to retrieve a value that may or
* may not exist, if the default null/zero is acceptable. For key/value
* pairs that do exist, `apply` (i.e. `map(key)`) is equally fast.
@@ -204,8 +204,8 @@ extends AbstractMap[Long, V]
if (i < 0) null.asInstanceOf[V] else _values(i).asInstanceOf[V]
}
}
-
- /** Retrieves the value associated with a key.
+
+ /** Retrieves the value associated with a key.
* If the key does not exist in the map, the `defaultEntry` for that key
* will be returned instead.
*/
@@ -220,12 +220,12 @@ extends AbstractMap[Long, V]
if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V]
}
}
-
+
/** The user-supplied default value for the key. Throws an exception
* if no other default behavior was specified.
*/
override def default(key: Long) = defaultEntry(key)
-
+
private def repack(newMask: Int) {
val ok = _keys
val ov = _values
@@ -244,9 +244,9 @@ extends AbstractMap[Long, V]
i += 1
}
}
-
+
/** Repacks the contents of this `LongMap` for maximum efficiency of lookup.
- *
+ *
* For maps that undergo a complex creation process with both addition and
* removal of keys, and then are used heavily with no further removal of
* elements, calling `repack` after the end of the creation can result in
@@ -259,7 +259,7 @@ extends AbstractMap[Long, V]
while (m > 8 && 8*_size < m) m = m >>> 1
repack(m)
}
-
+
override def put(key: Long, value: V): Option[V] = {
if (key == -key) {
if (key == 0) {
@@ -294,9 +294,9 @@ extends AbstractMap[Long, V]
}
}
}
-
+
/** Updates the map to include a new key-value pair.
- *
+ *
* This is the fastest way to add an entry to a `LongMap`.
*/
override def update(key: Long, value: V): Unit = {
@@ -326,12 +326,12 @@ extends AbstractMap[Long, V]
}
}
}
-
+
/** Adds a new key/value pair to this map and returns the map. */
def +=(key: Long, value: V): this.type = { update(key, value); this }
-
+
def +=(kv: (Long, V)): this.type = { update(kv._1, kv._2); this }
-
+
def -=(key: Long): this.type = {
if (key == -key) {
if (key == 0L) {
@@ -354,22 +354,22 @@ extends AbstractMap[Long, V]
}
this
}
-
+
def iterator: Iterator[(Long, V)] = new Iterator[(Long, V)] {
private[this] val kz = _keys
private[this] val vz = _values
-
- private[this] var nextPair: (Long, V) =
+
+ private[this] var nextPair: (Long, V) =
if (extraKeys==0) null
else if ((extraKeys&1)==1) (0L, zeroValue.asInstanceOf[V])
else (Long.MinValue, minValue.asInstanceOf[V])
- private[this] var anotherPair: (Long, V) =
+ private[this] var anotherPair: (Long, V) =
if (extraKeys==3) (Long.MinValue, minValue.asInstanceOf[V])
else null
-
+
private[this] var index = 0
-
+
def hasNext: Boolean = nextPair != null || (index < kz.length && {
var q = kz(index)
while (q == -q) {
@@ -392,8 +392,8 @@ extends AbstractMap[Long, V]
ans
}
}
-
- override def foreach[A](f: ((Long,V)) => A) {
+
+ override def foreach[U](f: ((Long,V)) => U) {
if ((extraKeys & 1) == 1) f((0L, zeroValue.asInstanceOf[V]))
if ((extraKeys & 2) == 2) f((Long.MinValue, minValue.asInstanceOf[V]))
var i,j = 0
@@ -406,7 +406,7 @@ extends AbstractMap[Long, V]
i += 1
}
}
-
+
override def clone(): LongMap[V] = {
val kz = java.util.Arrays.copyOf(_keys, _keys.length)
val vz = java.util.Arrays.copyOf(_values, _values.length)
@@ -414,19 +414,19 @@ extends AbstractMap[Long, V]
lm.initializeTo(mask, extraKeys, zeroValue, minValue, _size, _vacant, kz, vz)
lm
}
-
+
override def +[V1 >: V](kv: (Long, V1)): LongMap[V1] = {
val lm = clone().asInstanceOf[LongMap[V1]]
lm += kv
lm
}
-
+
override def ++[V1 >: V](xs: GenTraversableOnce[(Long, V1)]): LongMap[V1] = {
val lm = clone().asInstanceOf[LongMap[V1]]
xs.foreach(kv => lm += kv)
lm
}
-
+
override def updated[V1 >: V](key: Long, value: V1): LongMap[V1] = {
val lm = clone().asInstanceOf[LongMap[V1]]
lm += (key, value)
@@ -462,7 +462,7 @@ extends AbstractMap[Long, V]
i += 1
}
}
-
+
/** Creates a new `LongMap` with different values.
* Unlike `mapValues`, this method generates a new
* collection immediately.
@@ -485,8 +485,8 @@ extends AbstractMap[Long, V]
lm.initializeTo(mask, extraKeys, zv, mv, _size, _vacant, kz, vz)
lm
}
-
- /** Applies a transformation function to all values stored in this map.
+
+ /** Applies a transformation function to all values stored in this map.
* Note: the default, if any, is not transformed.
*/
def transformValues(f: V => V): this.type = {
@@ -510,15 +510,15 @@ object LongMap {
private final val MissingBit = 0x80000000
private final val VacantBit = 0x40000000
private final val MissVacant = 0xC0000000
-
+
private val exceptionDefault: Long => Nothing = (k: Long) => throw new NoSuchElementException(k.toString)
-
- implicit def canBuildFrom[V, U]: CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] =
+
+ implicit def canBuildFrom[V, U]: CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] =
new CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] {
def apply(from: LongMap[V]): LongMapBuilder[U] = apply()
def apply(): LongMapBuilder[U] = new LongMapBuilder[U]
}
-
+
final class LongMapBuilder[V] extends Builder[(Long, V), LongMap[V]] {
private[collection] var elems: LongMap[V] = new LongMap[V]
def +=(entry: (Long, V)): this.type = {
@@ -537,14 +537,14 @@ object LongMap {
if (lm.size < (sz>>3)) lm.repack()
lm
}
-
+
/** Creates a new empty `LongMap`. */
def empty[V]: LongMap[V] = new LongMap[V]
-
+
/** Creates a new empty `LongMap` with the supplied default */
def withDefault[V](default: Long => V): LongMap[V] = new LongMap[V](default)
-
- /** Creates a new `LongMap` from arrays of keys and values.
+
+ /** Creates a new `LongMap` from arrays of keys and values.
* Equivalent to but more efficient than `LongMap((keys zip values): _*)`.
*/
def fromZip[V](keys: Array[Long], values: Array[V]): LongMap[V] = {
@@ -555,8 +555,8 @@ object LongMap {
if (lm.size < (sz>>3)) lm.repack()
lm
}
-
- /** Creates a new `LongMap` from keys and values.
+
+ /** Creates a new `LongMap` from keys and values.
* Equivalent to but more efficient than `LongMap((keys zip values): _*)`.
*/
def fromZip[V](keys: collection.Iterable[Long], values: collection.Iterable[V]): LongMap[V] = {
diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala
index 40a5c93064..a19130e742 100644
--- a/src/library/scala/collection/mutable/SetLike.scala
+++ b/src/library/scala/collection/mutable/SetLike.scala
@@ -140,7 +140,9 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
/** Removes all elements from the set. After this operation is completed,
* the set will be empty.
*/
- def clear() { foreach(-=) }
+ def clear(): Unit =
+ for (elem <- this.toList)
+ this -= elem
override def clone(): This = empty ++= repr.seq
diff --git a/src/library/scala/collection/mutable/SynchronizedSet.scala b/src/library/scala/collection/mutable/SynchronizedSet.scala
index 60e2e79d3f..dd842f26ce 100644
--- a/src/library/scala/collection/mutable/SynchronizedSet.scala
+++ b/src/library/scala/collection/mutable/SynchronizedSet.scala
@@ -78,7 +78,7 @@ trait SynchronizedSet[A] extends Set[A] {
super.subsetOf(that)
}
- override def foreach[U](f: A => U) = synchronized {
+ override def foreach[U](f: A => U) = synchronized {
super.foreach(f)
}
diff --git a/src/library/scala/collection/package.scala b/src/library/scala/collection/package.scala
index 13fe7a79c4..856f901b77 100644
--- a/src/library/scala/collection/package.scala
+++ b/src/library/scala/collection/package.scala
@@ -13,8 +13,11 @@ package scala
*
* == Guide ==
*
- * A detailed guide for the collections library is available
+ * A detailed guide for using the collections library is available
* at [[http://docs.scala-lang.org/overviews/collections/introduction.html]].
+ * Developers looking to extend the collections library can find a description
+ * of its architecture at
+ * [[http://docs.scala-lang.org/overviews/core/architecture-of-scala-collections.html]].
*
* == Using Collections ==
*
@@ -31,24 +34,25 @@ package scala
* array: Array[Int] = Array(1, 2, 3, 4, 5, 6)
*
* scala> array map { _.toString }
- * res0: Array[java.lang.String] = Array(1, 2, 3, 4, 5, 6)
+ * res0: Array[String] = Array(1, 2, 3, 4, 5, 6)
*
* scala> val list = List(1,2,3,4,5,6)
* list: List[Int] = List(1, 2, 3, 4, 5, 6)
*
* scala> list map { _.toString }
- * res1: List[java.lang.String] = List(1, 2, 3, 4, 5, 6)
+ * res1: List[String] = List(1, 2, 3, 4, 5, 6)
*
* }}}
*
* == Creating Collections ==
*
- * The most common way to create a collection is to use the companion objects as factories.
- * Of these, the three most common
- * are [[scala.collection.Seq]], [[scala.collection.immutable.Set]], and [[scala.collection.immutable.Map]]. Their
- * companion objects are all available
- * as type aliases the either the [[scala]] package or in `scala.Predef`, and can be used
- * like so:
+ * The most common way to create a collection is to use its companion object as
+ * a factory. The three most commonly used collections are
+ * [[scala.collection.Seq]], [[scala.collection.immutable.Set]], and
+ * [[scala.collection.immutable.Map]].
+ * They can be used directly as shown below since their companion objects are
+ * all available as type aliases in either the [[scala]] package or in
+ * `scala.Predef`. New collections are created like this:
* {{{
* scala> val seq = Seq(1,2,3,4,1)
* seq: Seq[Int] = List(1, 2, 3, 4, 1)
@@ -56,12 +60,12 @@ package scala
* scala> val set = Set(1,2,3,4,1)
* set: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)
*
- * scala> val map = Map(1 -> "one",2 -> "two", 3 -> "three",2 -> "too")
- * map: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,one), (2,too), (3,three))
+ * scala> val map = Map(1 -> "one", 2 -> "two", 3 -> "three", 2 -> "too")
+ * map: scala.collection.immutable.Map[Int,String] = Map(1 -> one, 2 -> too, 3 -> three)
* }}}
*
- * It is also typical to use the [[scala.collection.immutable]] collections over those
- * in [[scala.collection.mutable]]; The types aliased in
+ * It is also typical to prefer the [[scala.collection.immutable]] collections
+ * over those in [[scala.collection.mutable]]; the types aliased in
* the `scala.Predef` object are the immutable versions.
*
* Also note that the collections library was carefully designed to include several implementations of
@@ -74,9 +78,13 @@ package scala
*
* === Converting between Java Collections ===
*
- * The `JavaConversions` object provides implicit defs that will allow mostly seamless integration
- * between Java Collections-based APIs and the Scala collections library.
+ * The [[scala.collection.JavaConversions]] object provides implicit defs that
+ * will allow mostly seamless integration between APIs using Java Collections
+ * and the Scala collections library.
*
+ * Alternatively the [[scala.collection.JavaConverters]] object provides a collection
+ * of decorators that allow converting between Scala and Java collections using `asScala`
+ * and `asJava` methods.
*/
package object collection {
import scala.collection.generic.CanBuildFrom
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala
index a5a82764d6..44df7f7260 100644
--- a/src/library/scala/collection/parallel/ParIterableLike.scala
+++ b/src/library/scala/collection/parallel/ParIterableLike.scala
@@ -1499,5 +1499,4 @@ self: ParIterableLike[T, Repr, Sequential] =>
append(s)
}
})
-
}
diff --git a/src/library/scala/collection/parallel/ParMapLike.scala b/src/library/scala/collection/parallel/ParMapLike.scala
index ee1334ba55..0a671fb085 100644
--- a/src/library/scala/collection/parallel/ParMapLike.scala
+++ b/src/library/scala/collection/parallel/ParMapLike.scala
@@ -99,14 +99,14 @@ self =>
def - (elem: K): ParSet[K] =
(ParSet[K]() ++ this - elem).asInstanceOf[ParSet[K]] // !!! concrete overrides abstract problem
override def size = self.size
- override def foreach[S](f: K => S) = for ((k, v) <- self) f(k)
+ override def foreach[U](f: K => U) = for ((k, v) <- self) f(k)
override def seq = self.seq.keySet
}
protected class DefaultValuesIterable extends ParIterable[V] {
def splitter = valuesIterator(self.splitter)
override def size = self.size
- override def foreach[S](f: V => S) = for ((k, v) <- self) f(v)
+ override def foreach[U](f: V => U) = for ((k, v) <- self) f(v)
def seq = self.seq.values
}
@@ -118,7 +118,7 @@ self =>
def filterKeys(p: K => Boolean): ParMap[K, V] = new ParMap[K, V] {
lazy val filtered = self.filter(kv => p(kv._1))
- override def foreach[S](f: ((K, V)) => S): Unit = for (kv <- self) if (p(kv._1)) f(kv)
+ override def foreach[U](f: ((K, V)) => U): Unit = for (kv <- self) if (p(kv._1)) f(kv)
def splitter = filtered.splitter
override def contains(key: K) = self.contains(key) && p(key)
def get(key: K) = if (!p(key)) None else self.get(key)
@@ -129,7 +129,7 @@ self =>
}
def mapValues[S](f: V => S): ParMap[K, S] = new ParMap[K, S] {
- override def foreach[Q](g: ((K, S)) => Q): Unit = for ((k, v) <- self) g((k, f(v)))
+ override def foreach[U](g: ((K, S)) => U): Unit = for ((k, v) <- self) g((k, f(v)))
def splitter = self.splitter.map(kv => (kv._1, f(kv._2)))
override def size = self.size
override def contains(key: K) = self.contains(key)