diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-11-24 10:17:40 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-11-24 10:17:40 +0100 |
commit | 86300fe1b3ab87b2e40616ed78709e8f03e707b5 (patch) | |
tree | 4458169015b02ecf7e29f805d0dbd6645171620a /src/library/scala/collection/immutable | |
parent | 3d0cbf9d10416fab8017b5fb46af44f59ee89fd1 (diff) | |
parent | 8eb1d4c29d85aef7828eeb35169e80c085cea93e (diff) | |
download | scala-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/scala/collection/immutable')
11 files changed, 31 insertions, 32 deletions
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 |