summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2010-04-05 13:47:27 +0000
committerMartin Odersky <odersky@gmail.com>2010-04-05 13:47:27 +0000
commitd59bde5a111dbdd40821c3bae4a956cc53db992e (patch)
tree8156d2bbdd226d154218ddac9b77599c7f1ae95f
parentedc621d245520a3b8a9ceabeb06b5c31ace98ae0 (diff)
downloadscala-d59bde5a111dbdd40821c3bae4a956cc53db992e.tar.gz
scala-d59bde5a111dbdd40821c3bae4a956cc53db992e.tar.bz2
scala-d59bde5a111dbdd40821c3bae4a956cc53db992e.zip
Rearranging IndexedSeq/LinearSeq and related work
-rw-r--r--src/library/scala/Array.scala10
-rw-r--r--src/library/scala/collection/IndexedSeq.scala10
-rw-r--r--src/library/scala/collection/IndexedSeqLike.scala274
-rwxr-xr-xsrc/library/scala/collection/IndexedSeqOptimized.scala293
-rw-r--r--src/library/scala/collection/IndexedSeqView.scala38
-rw-r--r--src/library/scala/collection/IndexedSeqViewLike.scala106
-rw-r--r--src/library/scala/collection/LinearSeq.scala12
-rw-r--r--src/library/scala/collection/LinearSeqLike.scala285
-rwxr-xr-xsrc/library/scala/collection/LinearSeqOptimized.scala301
-rw-r--r--src/library/scala/collection/SeqLike.scala4
-rw-r--r--src/library/scala/collection/TraversableViewLike.scala1
-rw-r--r--src/library/scala/collection/generic/TraversableView.scala.1152
-rw-r--r--src/library/scala/collection/immutable/IndexedSeq.scala5
-rw-r--r--src/library/scala/collection/immutable/IntMap.scala3
-rw-r--r--src/library/scala/collection/immutable/LinearSeq.scala2
-rw-r--r--src/library/scala/collection/immutable/List.scala2
-rw-r--r--src/library/scala/collection/immutable/LongMap.scala2
-rw-r--r--src/library/scala/collection/immutable/RedBlack.scala3
-rw-r--r--src/library/scala/collection/immutable/Stack.scala2
-rw-r--r--src/library/scala/collection/immutable/Stream.scala2
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayBuffer.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayLike.scala2
-rw-r--r--src/library/scala/collection/mutable/ArraySeq.scala (renamed from src/library/scala/collection/mutable/GenericArray.scala)16
-rw-r--r--src/library/scala/collection/mutable/FlatHashTable.scala2
-rw-r--r--src/library/scala/collection/mutable/IndexedSeq.scala3
-rwxr-xr-xsrc/library/scala/collection/mutable/IndexedSeqOptimized.scala21
-rw-r--r--src/library/scala/collection/mutable/IndexedSeqView.scala5
-rw-r--r--src/library/scala/collection/mutable/LinearSeq.scala1
-rw-r--r--src/library/scala/collection/mutable/ListMap.scala2
-rw-r--r--src/library/scala/collection/mutable/MutableList.scala2
-rw-r--r--src/library/scala/collection/mutable/ResizableArray.scala2
-rw-r--r--src/library/scala/math/Numeric.scala15
-rw-r--r--src/library/scala/runtime/RichChar.scala24
-rw-r--r--src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala2
35 files changed, 708 insertions, 900 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index 173883b41d..a7d27d0b9d 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -12,7 +12,7 @@
package scala
import scala.collection.generic._
-import scala.collection.mutable.{ArrayBuilder, GenericArray}
+import scala.collection.mutable.{ArrayBuilder, ArraySeq}
import compat.Platform.arraycopy
import scala.reflect.ClassManifest
import scala.runtime.ScalaRunTime.{array_apply, array_update}
@@ -29,10 +29,10 @@ class FallbackArrayBuilding {
* by Array.canBuildFrom). We make sure that that implicit search is always
* succesfull.
*/
- implicit def fallbackCanBuildFrom[T](implicit m: DummyImplicit): CanBuildFrom[Array[_], T, GenericArray[T]] =
- new CanBuildFrom[Array[_], T, GenericArray[T]] {
- def apply(from: Array[_]) = GenericArray.newBuilder[T]
- def apply() = GenericArray.newBuilder[T]
+ implicit def fallbackCanBuildFrom[T](implicit m: DummyImplicit): CanBuildFrom[Array[_], T, ArraySeq[T]] =
+ new CanBuildFrom[Array[_], T, ArraySeq[T]] {
+ def apply(from: Array[_]) = ArraySeq.newBuilder[T]
+ def apply() = ArraySeq.newBuilder[T]
}
}
diff --git a/src/library/scala/collection/IndexedSeq.scala b/src/library/scala/collection/IndexedSeq.scala
index 05141fb864..50a66e924c 100644
--- a/src/library/scala/collection/IndexedSeq.scala
+++ b/src/library/scala/collection/IndexedSeq.scala
@@ -14,15 +14,9 @@ package scala.collection
import generic._
import mutable.Builder
-/** <p>
- * Sequences that support O(1) element access and O(1) length computation.
- * </p>
- * <p>
- * This class does not add any methods to <code>Sequence</code> but
- * overrides several methods with optimized implementations.
- * </p>
+/** A base trait for indexed sequences.
+ * $indexedSeqInfo
*
- * @author Sean McDirmid
* @author Martin Odersky
* @version 2.8
* @since 2.8
diff --git a/src/library/scala/collection/IndexedSeqLike.scala b/src/library/scala/collection/IndexedSeqLike.scala
index 8164075629..ea6e1bb493 100644
--- a/src/library/scala/collection/IndexedSeqLike.scala
+++ b/src/library/scala/collection/IndexedSeqLike.scala
@@ -18,16 +18,23 @@ import scala.annotation.tailrec
/** A template trait for indexed sequences of type `IndexedSeq[A]`.
*
* $indexedSeqInfo
+ *
+ * This trait just implements `iterator` in terms of `apply` and `length`.
+ * However, see `IndexedSeqOptimized` for an implementation trait that overrides operations
+ * to make them run faster under the assumption of fast random access with `apply`.
+ *
* @author Sean McDirmid
* @author Martin Odersky
* @version 2.8
* @since 2.8
+ * @define Coll IndexedSeq
* @define indexedSeqInfo
* Indexed sequences support constant-time or near constant-time element
- * access and length computation.
+ * access and length computation. They are defined in terms of abstract methods
+ * `apply` fpor indexing and `length`.
*
- * Indexed sequences do not define any new methods wrt `Seq`. However, some `Seq` methods
- * are overridden with optimized implementations.
+ * Indexed sequences do not add any new methods wrt `Seq`, but promise
+ * efficient implementations of random access patterns.
*
* @tparam A the element type of the $coll
* @tparam Repr the type of the actual $coll containing the elements.
@@ -76,267 +83,7 @@ trait IndexedSeqLike[+A, +Repr] extends SeqLike[A, Repr] { self =>
override /*IterableLike*/
def iterator: Iterator[A] = new Elements(0, length)
-
- override /*IterableLike*/
- def isEmpty: Boolean = { length == 0 }
-
- override /*IterableLike*/
- def foreach[U](f: A => U): Unit = {
- var i = 0
- val len = length
- while (i < len) { f(this(i)); i += 1 }
- }
-
- override /*IterableLike*/
- def forall(p: A => Boolean): Boolean = prefixLength(p(_)) == length
-
- override /*IterableLike*/
- def exists(p: A => Boolean): Boolean = prefixLength(!p(_)) != length
-
- override /*IterableLike*/
- def find(p: A => Boolean): Option[A] = {
- val i = prefixLength(!p(_))
- if (i < length) Some(this(i)) else None
- }
/*
- override /*IterableLike*/
- def mapFind[B](f: A => Option[B]): Option[B] = {
- var i = 0
- var res: Option[B] = None
- val len = length
- while (res.isEmpty && i < len) {
- res = f(this(i))
- i += 1
- }
- res
- }
-*/
- @tailrec
- private def foldl[B](start: Int, end: Int, z: B, op: (B, A) => B): B =
- if (start == end) z
- else foldl(start + 1, end, op(z, this(start)), op)
-
- @tailrec
- private def foldr[B](start: Int, end: Int, z: B, op: (A, B) => B): B =
- if (start == end) z
- else foldr(start, end - 1, op(this(end - 1), z), op)
-
- override /*TraversableLike*/
- def foldLeft[B](z: B)(op: (B, A) => B): B =
- foldl(0, length, z, op)
-
- override /*IterableLike*/
- def foldRight[B](z: B)(op: (A, B) => B): B =
- foldr(0, length, z, op)
-
- override /*TraversableLike*/
- def reduceLeft[B >: A](op: (B, A) => B): B =
- if (length > 0) foldl(1, length, this(0), op) else super.reduceLeft(op)
-
- override /*IterableLike*/
- def reduceRight[B >: A](op: (A, B) => B): B =
- if (length > 0) foldr(0, length - 1, this(length - 1), op) else super.reduceRight(op)
-
- override /*IterableLike*/
- def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = that match {
- case that: IndexedSeq[_] =>
- val b = bf(repr)
- var i = 0
- val len = this.length min that.length
- b.sizeHint(len)
- while (i < len) {
- b += ((this(i), that(i).asInstanceOf[B]))
- i += 1
- }
- b.result
- case _ =>
- super.zip[A1, B, That](that)(bf)
- }
-
- override /*IterableLike*/
- def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Repr, (A1, Int), That]): That = {
- val b = bf(repr)
- val len = length
- b.sizeHint(len)
- var i = 0
- while (i < len) {
- b += ((this(i), i))
- i += 1
- }
- b.result
- }
-
- override /*IterableLike*/
- def slice(from: Int, until: Int): Repr = {
- var i = from max 0
- val end = until min length
- val b = newBuilder
- b.sizeHint(end - i)
- while (i < end) {
- b += this(i)
- i += 1
- }
- b.result
- }
-
- override /*IterableLike*/
- def head: A = if (isEmpty) super.head else this(0)
-
- override /*TraversableLike*/
- def tail: Repr = if (isEmpty) super.tail else slice(1, length)
-
- override /*TraversableLike*/
- def last: A = if (length > 0) this(length - 1) else super.last
-
- override /*IterableLike*/
- def init: Repr = if (length > 0) slice(0, length - 1) else super.init
-
- override /*TraversableLike*/
- def take(n: Int): Repr = slice(0, n)
-
- override /*TraversableLike*/
- def drop(n: Int): Repr = slice(n, length)
-
- override /*IterableLike*/
- def takeRight(n: Int): Repr = slice(length - n, length)
-
- override /*IterableLike*/
- def dropRight(n: Int): Repr = slice(0, length - n)
-
- override /*TraversableLike*/
- def splitAt(n: Int): (Repr, Repr) = (take(n), drop(n))
-
- override /*IterableLike*/
- def takeWhile(p: A => Boolean): Repr = take(prefixLength(p))
-
- override /*TraversableLike*/
- def dropWhile(p: A => Boolean): Repr = drop(prefixLength(p))
-
- override /*TraversableLike*/
- def span(p: A => Boolean): (Repr, Repr) = splitAt(prefixLength(p))
-
- override /*IterableLike*/
- def sameElements[B >: A](that: Iterable[B]): Boolean = that match {
- case that: IndexedSeq[_] =>
- val len = length
- len == that.length && {
- var i = 0
- while (i < len && this(i) == that(i)) i += 1
- i == len
- }
- case _ =>
- super.sameElements(that)
- }
-
- override /*IterableLike*/
- def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
- var i = 0
- var j = start
- val end = length min len min (xs.length - start)
- while (i < end) {
- xs(j) = this(i)
- i += 1
- j += 1
- }
- }
-
-
- // Overridden methods from Seq
-
- override /*SeqLike*/
- def lengthCompare(len: Int): Int = length - len
-
- override /*SeqLike*/
- def segmentLength(p: A => Boolean, from: Int): Int = {
- val start = from
- val len = length
- var i = start
- while (i < len && p(this(i))) i += 1
- i - start
- }
-
- private def negLength(n: Int) = if (n == length) -1 else n
-
- override /*SeqLike*/
- def indexWhere(p: A => Boolean, from: Int): Int = {
- val start = from max 0
- negLength(start + segmentLength(!p(_), start))
- }
-
- override /*SeqLike*/
- def lastIndexWhere(p: A => Boolean, end: Int): Int = {
- var i = end
- while (i >= 0 && !p(this(i))) i -= 1
- i
- }
-
- override /*SeqLike*/
- def reverse: Repr = {
- val b = newBuilder
- b.sizeHint(length)
- var i = length
- while (0 < i) {
- i -= 1
- b += this(i)
- }
- b.result
- }
-
- override /*SeqLike*/
- def reverseIterator: Iterator[A] = new Iterator[A] {
- private var i = self.length
- def hasNext: Boolean = 0 < i
- def next: A =
- if (0 < i) {
- i -= 1
- self(i)
- } else Iterator.empty.next
- }
-
- override /*SeqLike*/
- def startsWith[B](that: Seq[B], offset: Int): Boolean = that match {
- case that: IndexedSeq[_] =>
- var i = offset
- var j = 0
- val thisLen = length
- val thatLen = that.length
- while (i < thisLen && j < thatLen && this(i) == that(j)) {
- i += 1
- j += 1
- }
- j == thatLen
- case _ =>
- var i = offset
- val thisLen = length
- val thatElems = that.iterator
- while (i < thisLen && thatElems.hasNext) {
- if (this(i) != thatElems.next())
- return false
-
- i += 1
- }
- !thatElems.hasNext
- }
-
- override /*SeqLike*/
- def endsWith[B](that: Seq[B]): Boolean = that match {
- case that: IndexedSeq[_] =>
- var i = length - 1
- var j = that.length - 1
-
- (j <= i) && {
- while (j >= 0) {
- if (this(i) != that(j))
- return false
- i -= 1
- j -= 1
- }
- true
- }
- case _ =>
- super.endsWith(that)
- }
-
override /*SeqLike*/
def view = new IndexedSeqView[A, Repr] {
protected lazy val underlying = self.repr
@@ -347,5 +94,6 @@ trait IndexedSeqLike[+A, +Repr] extends SeqLike[A, Repr] { self =>
override /*SeqLike*/
def view(from: Int, until: Int) = view.slice(from, until)
+*/
}
diff --git a/src/library/scala/collection/IndexedSeqOptimized.scala b/src/library/scala/collection/IndexedSeqOptimized.scala
new file mode 100755
index 0000000000..12b39c8b83
--- /dev/null
+++ b/src/library/scala/collection/IndexedSeqOptimized.scala
@@ -0,0 +1,293 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: IndexedSeqLike.scala 20129 2009-12-14 17:12:17Z odersky $
+
+
+package scala.collection
+
+import generic._
+import mutable.ArrayBuffer
+import scala.annotation.tailrec
+
+/** A template trait for indexed sequences of type `IndexedSeq[A]` which optimizes
+ * the implementation of several methods under the assumption of fast random access.
+ *
+ * $indexedSeqInfo
+ * @author Martin Odersky
+ * @version 2.8
+ * @since 2.8
+ *
+ * @tparam A the element type of the $coll
+ * @tparam Repr the type of the actual $coll containing the elements.
+ * @define willNotTerminateInf
+ * @define mayNotTerminateInf
+ */
+trait IndexedSeqOptimized[+A, +Repr] extends IndexedSeqLike[A, Repr] { self =>
+
+ override /*IterableLike*/
+ def isEmpty: Boolean = { length == 0 }
+
+ override /*IterableLike*/
+ def foreach[U](f: A => U): Unit = {
+ var i = 0
+ val len = length
+ while (i < len) { f(this(i)); i += 1 }
+ }
+
+ override /*IterableLike*/
+ def forall(p: A => Boolean): Boolean = prefixLength(p(_)) == length
+
+ override /*IterableLike*/
+ def exists(p: A => Boolean): Boolean = prefixLength(!p(_)) != length
+
+ override /*IterableLike*/
+ def find(p: A => Boolean): Option[A] = {
+ val i = prefixLength(!p(_))
+ if (i < length) Some(this(i)) else None
+ }
+/*
+ override /*IterableLike*/
+ def mapFind[B](f: A => Option[B]): Option[B] = {
+ var i = 0
+ var res: Option[B] = None
+ val len = length
+ while (res.isEmpty && i < len) {
+ res = f(this(i))
+ i += 1
+ }
+ res
+ }
+*/
+ @tailrec
+ private def foldl[B](start: Int, end: Int, z: B, op: (B, A) => B): B =
+ if (start == end) z
+ else foldl(start + 1, end, op(z, this(start)), op)
+
+ @tailrec
+ private def foldr[B](start: Int, end: Int, z: B, op: (A, B) => B): B =
+ if (start == end) z
+ else foldr(start, end - 1, op(this(end - 1), z), op)
+
+ override /*TraversableLike*/
+ def foldLeft[B](z: B)(op: (B, A) => B): B =
+ foldl(0, length, z, op)
+
+ override /*IterableLike*/
+ def foldRight[B](z: B)(op: (A, B) => B): B =
+ foldr(0, length, z, op)
+
+ override /*TraversableLike*/
+ def reduceLeft[B >: A](op: (B, A) => B): B =
+ if (length > 0) foldl(1, length, this(0), op) else super.reduceLeft(op)
+
+ override /*IterableLike*/
+ def reduceRight[B >: A](op: (A, B) => B): B =
+ if (length > 0) foldr(0, length - 1, this(length - 1), op) else super.reduceRight(op)
+
+ override /*IterableLike*/
+ def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = that match {
+ case that: IndexedSeq[_] =>
+ val b = bf(repr)
+ var i = 0
+ val len = this.length min that.length
+ b.sizeHint(len)
+ while (i < len) {
+ b += ((this(i), that(i).asInstanceOf[B]))
+ i += 1
+ }
+ b.result
+ case _ =>
+ super.zip[A1, B, That](that)(bf)
+ }
+
+ override /*IterableLike*/
+ def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Repr, (A1, Int), That]): That = {
+ val b = bf(repr)
+ val len = length
+ b.sizeHint(len)
+ var i = 0
+ while (i < len) {
+ b += ((this(i), i))
+ i += 1
+ }
+ b.result
+ }
+
+ override /*IterableLike*/
+ def slice(from: Int, until: Int): Repr = {
+ var i = from max 0
+ val end = until min length
+ val b = newBuilder
+ b.sizeHint(end - i)
+ while (i < end) {
+ b += this(i)
+ i += 1
+ }
+ b.result
+ }
+
+ override /*IterableLike*/
+ def head: A = if (isEmpty) super.head else this(0)
+
+ override /*TraversableLike*/
+ def tail: Repr = if (isEmpty) super.tail else slice(1, length)
+
+ override /*TraversableLike*/
+ def last: A = if (length > 0) this(length - 1) else super.last
+
+ override /*IterableLike*/
+ def init: Repr = if (length > 0) slice(0, length - 1) else super.init
+
+ override /*TraversableLike*/
+ def take(n: Int): Repr = slice(0, n)
+
+ override /*TraversableLike*/
+ def drop(n: Int): Repr = slice(n, length)
+
+ override /*IterableLike*/
+ def takeRight(n: Int): Repr = slice(length - n, length)
+
+ override /*IterableLike*/
+ def dropRight(n: Int): Repr = slice(0, length - n)
+
+ override /*TraversableLike*/
+ def splitAt(n: Int): (Repr, Repr) = (take(n), drop(n))
+
+ override /*IterableLike*/
+ def takeWhile(p: A => Boolean): Repr = take(prefixLength(p))
+
+ override /*TraversableLike*/
+ def dropWhile(p: A => Boolean): Repr = drop(prefixLength(p))
+
+ override /*TraversableLike*/
+ def span(p: A => Boolean): (Repr, Repr) = splitAt(prefixLength(p))
+
+ override /*IterableLike*/
+ def sameElements[B >: A](that: Iterable[B]): Boolean = that match {
+ case that: IndexedSeq[_] =>
+ val len = length
+ len == that.length && {
+ var i = 0
+ while (i < len && this(i) == that(i)) i += 1
+ i == len
+ }
+ case _ =>
+ super.sameElements(that)
+ }
+
+ override /*IterableLike*/
+ def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
+ var i = 0
+ var j = start
+ val end = length min len min (xs.length - start)
+ while (i < end) {
+ xs(j) = this(i)
+ i += 1
+ j += 1
+ }
+ }
+
+
+ // Overridden methods from Seq
+
+ override /*SeqLike*/
+ def lengthCompare(len: Int): Int = length - len
+
+ override /*SeqLike*/
+ def segmentLength(p: A => Boolean, from: Int): Int = {
+ val start = from
+ val len = length
+ var i = start
+ while (i < len && p(this(i))) i += 1
+ i - start
+ }
+
+ private def negLength(n: Int) = if (n == length) -1 else n
+
+ override /*SeqLike*/
+ def indexWhere(p: A => Boolean, from: Int): Int = {
+ val start = from max 0
+ negLength(start + segmentLength(!p(_), start))
+ }
+
+ override /*SeqLike*/
+ def lastIndexWhere(p: A => Boolean, end: Int): Int = {
+ var i = end
+ while (i >= 0 && !p(this(i))) i -= 1
+ i
+ }
+
+ override /*SeqLike*/
+ def reverse: Repr = {
+ val b = newBuilder
+ b.sizeHint(length)
+ var i = length
+ while (0 < i) {
+ i -= 1
+ b += this(i)
+ }
+ b.result
+ }
+
+ override /*SeqLike*/
+ def reverseIterator: Iterator[A] = new Iterator[A] {
+ private var i = self.length
+ def hasNext: Boolean = 0 < i
+ def next: A =
+ if (0 < i) {
+ i -= 1
+ self(i)
+ } else Iterator.empty.next
+ }
+
+ override /*SeqLike*/
+ def startsWith[B](that: Seq[B], offset: Int): Boolean = that match {
+ case that: IndexedSeq[_] =>
+ var i = offset
+ var j = 0
+ val thisLen = length
+ val thatLen = that.length
+ while (i < thisLen && j < thatLen && this(i) == that(j)) {
+ i += 1
+ j += 1
+ }
+ j == thatLen
+ case _ =>
+ var i = offset
+ val thisLen = length
+ val thatElems = that.iterator
+ while (i < thisLen && thatElems.hasNext) {
+ if (this(i) != thatElems.next())
+ return false
+
+ i += 1
+ }
+ !thatElems.hasNext
+ }
+
+ override /*SeqLike*/
+ def endsWith[B](that: Seq[B]): Boolean = that match {
+ case that: IndexedSeq[_] =>
+ var i = length - 1
+ var j = that.length - 1
+
+ (j <= i) && {
+ while (j >= 0) {
+ if (this(i) != that(j))
+ return false
+ i -= 1
+ j -= 1
+ }
+ true
+ }
+ case _ =>
+ super.endsWith(that)
+ }
+}
+
diff --git a/src/library/scala/collection/IndexedSeqView.scala b/src/library/scala/collection/IndexedSeqView.scala
deleted file mode 100644
index 72f3374e94..0000000000
--- a/src/library/scala/collection/IndexedSeqView.scala
+++ /dev/null
@@ -1,38 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.collection
-
-import TraversableView.NoBuilder
-import generic._
-
-/** A non-strict projection of an iterable.
- *
- * @author Sean McDirmid
- * @author Martin Odersky
- * @version 2.8
- * @since 2.8
- */
-trait IndexedSeqView[+A, +Coll] extends IndexedSeqViewLike[A, Coll, IndexedSeqView[A, Coll]]
-
-object IndexedSeqView {
- type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]}
- implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeqView[A, IndexedSeq[_]]] =
- new CanBuildFrom[Coll, A, IndexedSeqView[A, IndexedSeq[_]]] {
- def apply(from: Coll) = new NoBuilder
- def apply() = new NoBuilder
- }
- implicit def arrCanBuildFrom[A]: CanBuildFrom[TraversableView[_, Array[_]], A, IndexedSeqView[A, Array[A]]] =
- new CanBuildFrom[TraversableView[_, Array[_]], A, IndexedSeqView[A, Array[A]]] {
- def apply(from: TraversableView[_, Array[_]]) = new NoBuilder
- def apply() = new NoBuilder
- }
-}
diff --git a/src/library/scala/collection/IndexedSeqViewLike.scala b/src/library/scala/collection/IndexedSeqViewLike.scala
deleted file mode 100644
index 4b829f82ac..0000000000
--- a/src/library/scala/collection/IndexedSeqViewLike.scala
+++ /dev/null
@@ -1,106 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Seq.scala 16092 2008-09-12 10:37:06Z nielsen $
-
-
-package scala.collection
-
-import generic._
-import TraversableView.NoBuilder
-
-/** A template trait for a non-strict view of a IndexedSeq.
- *
- * @author Sean McDirmid
- * @author Martin Odersky
- * @version 2.8
- * @since 2.8
- */
-trait IndexedSeqViewLike[+A,
- +Coll,
- +This <: IndexedSeqView[A, Coll] with IndexedSeqViewLike[A, Coll, This]]
- extends IndexedSeq[A] with IndexedSeqLike[A, This] with SeqView[A, Coll] with SeqViewLike[A, Coll, This]
-{ self =>
-
- trait Transformed[+B] extends IndexedSeqView[B, Coll] with super.Transformed[B] {
- /** Override to use IndexedSeq's foreach; todo: see whether this is really faster */
-// override def foreach[U](f: A => U)
- }
-
- trait Forced[B] extends Transformed[B] with super.Forced[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- trait Sliced extends Transformed[A] with super.Sliced {
- override def foreach[U](f: A => U) = super[Transformed].foreach(f)
- }
-
- trait Mapped[B] extends Transformed[B] with super.Mapped[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- trait FlatMapped[B] extends Transformed[B] with super.FlatMapped[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- trait Appended[B >: A] extends Transformed[B] with super.Appended[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- trait Filtered extends Transformed[A] with super.Filtered {
- override def foreach[U](f: A => U) = super[Transformed].foreach(f)
- }
-
- trait TakenWhile extends Transformed[A] with super.TakenWhile {
- override def foreach[U](f: A => U) = super[Transformed].foreach(f)
- }
-
- trait DroppedWhile extends Transformed[A] with super.DroppedWhile {
- override def foreach[U](f: A => U) = super[Transformed].foreach(f)
- }
-
- trait Reversed extends Transformed[A] with super.Reversed {
- override def foreach[U](f: A => U) = super[Transformed].foreach(f)
- }
-
- trait Patched[B >: A] extends Transformed[B] with super.Patched[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- trait Zipped[B] extends Transformed[(A, B)] with super.Zipped[B] {
- override def foreach[U](f: ((A, B)) => U) = super[Transformed].foreach(f)
- }
-
- trait ZippedAll[A1 >: A, B] extends Transformed[(A1, B)] with super.ZippedAll[A1, B] {
- override def foreach[U](f: ((A1, B)) => U) = super[Transformed].foreach(f)
- }
-
- trait Prepended[B >: A] extends Transformed[B] with super.Prepended[B] {
- override def foreach[U](f: B => U) = super[Transformed].foreach(f)
- }
-
- /** Boilerplate method, to override in each subclass
- * This method could be eliminated if Scala had virtual classes
- */
- protected override def newForced[B](xs: => Seq[B]): Transformed[B] = new Forced[B] { val forced = xs }
- protected override def newAppended[B >: A](that: Traversable[B]): Transformed[B] = new Appended[B] { val rest = that }
- protected override def newMapped[B](f: A => B): Transformed[B] = new Mapped[B] { val mapping = f }
- protected override def newFlatMapped[B](f: A => Traversable[B]): Transformed[B] = new FlatMapped[B] { val mapping = f }
- protected override def newFiltered(p: A => Boolean): Transformed[A] = new Filtered { val pred = p }
- protected override def newSliced(_from: Int, _until: Int): Transformed[A] = new Sliced { val from = _from; val until = _until }
- protected override def newDroppedWhile(p: A => Boolean): Transformed[A] = new DroppedWhile { val pred = p }
- protected override def newTakenWhile(p: A => Boolean): Transformed[A] = new TakenWhile { val pred = p }
- protected override def newZipped[B](that: Iterable[B]): Transformed[(A, B)] = new Zipped[B] { val other = that }
- protected override def newZippedAll[A1 >: A, B](that: Iterable[B], _thisElem: A1, _thatElem: B): Transformed[(A1, B)] = new ZippedAll[A1, B] { val other = that; val thisElem = _thisElem; val thatElem = _thatElem }
- protected override def newReversed: Transformed[A] = new Reversed { }
- protected override def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new Patched[B] {
- val from = _from; val patch = _patch; val replaced = _replaced
- }
- protected override def newPrepended[B >: A](elem: B): Transformed[B] = new Prepended[B] { protected[this] val fst = elem }
- override def stringPrefix = "IndexedSeqView"
-}
diff --git a/src/library/scala/collection/LinearSeq.scala b/src/library/scala/collection/LinearSeq.scala
index 5862741530..1afb2fdb7f 100644
--- a/src/library/scala/collection/LinearSeq.scala
+++ b/src/library/scala/collection/LinearSeq.scala
@@ -14,18 +14,10 @@ package scala.collection
import generic._
import mutable.Builder
-/** <p>
- * Class <code>Linear[A]</code> represents linear sequences of elements.
- * For such sequences <code>isEmpty</code>, <code>head</code> and
- * <code>tail</code> are guaranteed to be efficient constant time (or near so)
- * operations.<br/>
- * It does not add any methods to <code>Seq</code> but overrides several
- * methods with optimized implementations.
- * </p>
+/** A base trait for linear sequences.
+ * $linearSeqInfo
*
* @author Martin Odersky
- * @author Matthias Zenger
- * @version 1.0, 16/07/2003
* @since 2.8
*/
trait LinearSeq[+A] extends Seq[A]
diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala
index 665b760932..1c99d4a3d9 100644
--- a/src/library/scala/collection/LinearSeqLike.scala
+++ b/src/library/scala/collection/LinearSeqLike.scala
@@ -19,12 +19,16 @@ import scala.util.control.Breaks._
/** A template trait for linear sequences of type `LinearSeq[A]`.
*
* $linearSeqInfo
+ *
+ * This trait just implements `iterator`
+ * in terms of `isEmpty, ``head`, and `tail`.
+ * However, see `LinearSeqOptimized` for an implementation trait that overrides operations
+ * to make them run faster under the assumption of fast linear access with `head` and `tail`.
+ *
* @author Martin Odersky
- * @author Matthias Zenger
- * @version 1.0, 16/07/2003
+ * @version 2.8
* @since 2.8
*
- * @define Coll LinearSeq
* @define linearSeqInfo
* Linear sequences are defined in terms of three abstract methods, which are assumed
* to have efficient implementations. These are:
@@ -35,9 +39,8 @@ import scala.util.control.Breaks._
* }}}
* Here, `A` is the type of the sequence elements and `Repr` is the type of the sequence itself.
*
- * Linear sequences do not define any new methods wrt `Seq`. However, abstract `Seq` methods
- * are defined in terms of `isEmpty`, `head`, and `tail`, and several other methods are overridden
- * with optimized implementations.
+ * Linear sequences do not add any new methods to `Seq`, but promise efficient implementations
+ * of linear access patterns.
*
* @tparam A the element type of the $coll
* @tparam Repr the type of the actual $coll containing the elements.
@@ -47,38 +50,6 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr
override protected[this] def thisCollection: LinearSeq[A] = this.asInstanceOf[LinearSeq[A]]
override protected[this] def toCollection(repr: Repr): LinearSeq[A] = repr.asInstanceOf[LinearSeq[A]]
- def isEmpty: Boolean
-
- def head: A
-
- def tail: Repr
-
- /** The length of the $coll.
- *
- * $willNotTerminateInf
- *
- * Note: the execution of `length` may take time proportial to the length of the sequence.
- */
- def length: Int = {
- var these = self
- var len = 0
- while (!these.isEmpty) {
- len += 1
- these = these.tail
- }
- len
- }
-
- /** Selects an element by its index in the $coll.
- * Note: the execution of `apply` may take time proportial to the index value.
- * @throws `IndexOutOfBoundsEsxception` if `idx` does not satisfy `0 <= idx < length`.
- */
- def apply(n: Int): A = {
- val rest = drop(n)
- if (n < 0 || rest.isEmpty) throw new IndexOutOfBoundsException
- rest.head
- }
-
override /*IterableLike*/
def iterator: Iterator[A] = new Iterator[A] {
var these = self
@@ -89,242 +60,4 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr
} else Iterator.empty.next
override def toList: List[A] = these.toList
}
-
- override /*IterableLike*/
- def foreach[B](f: A => B) {
- var these = this
- while (!these.isEmpty) {
- f(these.head)
- these = these.tail
- }
- }
-
-
- override /*IterableLike*/
- def forall(p: A => Boolean): Boolean = {
- var these = this
- while (!these.isEmpty) {
- if (!p(these.head)) return false
- these = these.tail
- }
- true
- }
-
- override /*IterableLike*/
- def exists(p: A => Boolean): Boolean = {
- var these = this
- while (!these.isEmpty) {
- if (p(these.head)) return true
- these = these.tail
- }
- false
- }
-
- override /*TraversableLike*/
- def count(p: A => Boolean): Int = {
- var these = this
- var cnt = 0
- while (!these.isEmpty) {
- if (p(these.head)) cnt += 1
- these = these.tail
- }
- cnt
- }
-
- override /*IterableLike*/
- def find(p: A => Boolean): Option[A] = {
- var these = this
- while (!these.isEmpty) {
- if (p(these.head)) return Some(these.head)
- these = these.tail
- }
- None
- }
-/*
- override def mapFind[B](f: A => Option[B]): Option[B] = {
- var res: Option[B] = None
- var these = this
- while (res.isEmpty && !these.isEmpty) {
- res = f(these.head)
- these = these.tail
- }
- res
- }
-*/
- override /*TraversableLike*/
- def foldLeft[B](z: B)(f: (B, A) => B): B = {
- var acc = z
- var these = this
- while (!these.isEmpty) {
- acc = f(acc, these.head)
- these = these.tail
- }
- acc
- }
-
- override /*IterableLike*/
- def foldRight[B](z: B)(f: (A, B) => B): B =
- if (this.isEmpty) z
- else f(head, tail.foldRight(z)(f))
-
- override /*TraversableLike*/
- def reduceLeft[B >: A](f: (B, A) => B): B =
- if (isEmpty) throw new UnsupportedOperationException("empty.reduceLeft")
- else tail.foldLeft[B](head)(f)
-
- override /*IterableLike*/
- def reduceRight[B >: A](op: (A, B) => B): B =
- if (isEmpty) throw new UnsupportedOperationException("Nil.reduceRight")
- else if (tail.isEmpty) head
- else op(head, tail.reduceRight(op))
-
- override /*TraversableLike*/
- def last: A = {
- if (isEmpty) throw new NoSuchElementException
- var these = this
- var nx = these.tail
- while (!nx.isEmpty) {
- these = nx
- nx = nx.tail
- }
- these.head
- }
-
- override /*IterableLike*/
- def take(n: Int): Repr = {
- val b = newBuilder
- var i = 0
- var these = repr
- while (!these.isEmpty && i < n) {
- i += 1
- b += these.head
- these = these.tail
- }
- b.result
- }
-
- override /*TraversableLike*/
- def drop(n: Int): Repr = {
- var these: Repr = repr
- var count = n
- while (!these.isEmpty && count > 0) {
- these = these.tail
- count -= 1
- }
- these
- }
-
- override /*IterableLike*/
- def dropRight(n: Int): Repr = {
- val b = newBuilder
- var these = this
- var lead = this drop n
- while (!lead.isEmpty) {
- b += these.head
- these = these.tail
- lead = lead.tail
- }
- b.result
- }
-
- override /*IterableLike*/
- def slice(from: Int, until: Int): Repr = {
- val b = newBuilder
- var i = from
- var these = this drop from
- while (i < until && !these.isEmpty) {
- b += these.head
- these = these.tail
- i += 1
- }
- b.result
- }
-
- override /*IterableLike*/
- def takeWhile(p: A => Boolean): Repr = {
- val b = newBuilder
- var these = this
- while (!these.isEmpty && p(these.head)) {
- b += these.head
- these = these.tail
- }
- b.result
- }
-
- override /*TraversableLike*/
- def span(p: A => Boolean): (Repr, Repr) = {
- var these: Repr = repr
- val b = newBuilder
- while (!these.isEmpty && p(these.head)) {
- b += these.head
- these = these.tail
- }
- (b.result, these)
- }
-
- override /*IterableLike*/
- def sameElements[B >: A](that: Iterable[B]): Boolean = that match {
- case that1: LinearSeq[_] =>
- var these = this
- var those = that1
- while (!these.isEmpty && !those.isEmpty && these.head == those.head) {
- these = these.tail
- those = those.tail
- }
- these.isEmpty && those.isEmpty
- case _ =>
- super.sameElements(that)
- }
-
- override /*SeqLike*/
- def lengthCompare(len: Int): Int = {
- var i = 0
- var these = self
- while (!these.isEmpty && i <= len) {
- i += 1
- these = these.tail
- }
- i - len
- }
-
- override /*SeqLike*/
- def isDefinedAt(x: Int): Boolean = x >= 0 && lengthCompare(x) > 0
-
- override /*SeqLike*/
- def segmentLength(p: A => Boolean, from: Int): Int = {
- var i = 0
- var these = this drop from
- while (!these.isEmpty && p(these.head)) {
- i += 1
- these = these.tail
- }
- i
- }
-
- override /*SeqLike*/
- def indexWhere(p: A => Boolean, from: Int): Int = {
- var i = from
- var these = this drop from
- while (these.nonEmpty) {
- if (p(these.head))
- return i
-
- i += 1
- these = these.tail
- }
- -1
- }
-
- override /*SeqLike*/
- def lastIndexWhere(p: A => Boolean, end: Int): Int = {
- var i = 0
- var these = this
- var last = -1
- while (!these.isEmpty && i <= end) {
- if (p(these.head)) last = i
- these = these.tail
- i += 1
- }
- last
- }
}
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
new file mode 100755
index 0000000000..dda74da394
--- /dev/null
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -0,0 +1,301 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: LinearSeqOptimized.scala 20608 2010-01-20 00:28:09Z extempore $
+
+
+package scala.collection
+import generic._
+
+import mutable.ListBuffer
+import immutable.List
+import scala.util.control.Breaks._
+
+/** A template trait for linear sequences of type `LinearSeq[A]` which optimizes
+ * the implementation of several methods under the assumption of fast linear access.
+ *
+ * $linearSeqInfo
+ * @author Martin Odersky
+ * @version 2.8
+ * @since 2.8
+ *
+ * @tparam A the element type of the $coll
+ * @tparam Repr the type of the actual $coll containing the elements.
+ */
+trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends LinearSeqLike[A, Repr] { self: Repr =>
+
+ def isEmpty: Boolean
+
+ def head: A
+
+ def tail: Repr
+
+ /** The length of the $coll.
+ *
+ * $willNotTerminateInf
+ *
+ * Note: the execution of `length` may take time proportial to the length of the sequence.
+ */
+ def length: Int = {
+ var these = self
+ var len = 0
+ while (!these.isEmpty) {
+ len += 1
+ these = these.tail
+ }
+ len
+ }
+
+ /** Selects an element by its index in the $coll.
+ * Note: the execution of `apply` may take time proportial to the index value.
+ * @throws `IndexOutOfBoundsEsxception` if `idx` does not satisfy `0 <= idx < length`.
+ */
+ def apply(n: Int): A = {
+ val rest = drop(n)
+ if (n < 0 || rest.isEmpty) throw new IndexOutOfBoundsException
+ rest.head
+ }
+
+ override /*IterableLike*/
+ def foreach[B](f: A => B) {
+ var these = this
+ while (!these.isEmpty) {
+ f(these.head)
+ these = these.tail
+ }
+ }
+
+
+ override /*IterableLike*/
+ def forall(p: A => Boolean): Boolean = {
+ var these = this
+ while (!these.isEmpty) {
+ if (!p(these.head)) return false
+ these = these.tail
+ }
+ true
+ }
+
+ override /*IterableLike*/
+ def exists(p: A => Boolean): Boolean = {
+ var these = this
+ while (!these.isEmpty) {
+ if (p(these.head)) return true
+ these = these.tail
+ }
+ false
+ }
+
+ override /*TraversableLike*/
+ def count(p: A => Boolean): Int = {
+ var these = this
+ var cnt = 0
+ while (!these.isEmpty) {
+ if (p(these.head)) cnt += 1
+ these = these.tail
+ }
+ cnt
+ }
+
+ override /*IterableLike*/
+ def find(p: A => Boolean): Option[A] = {
+ var these = this
+ while (!these.isEmpty) {
+ if (p(these.head)) return Some(these.head)
+ these = these.tail
+ }
+ None
+ }
+/*
+ override def mapFind[B](f: A => Option[B]): Option[B] = {
+ var res: Option[B] = None
+ var these = this
+ while (res.isEmpty && !these.isEmpty) {
+ res = f(these.head)
+ these = these.tail
+ }
+ res
+ }
+*/
+ override /*TraversableLike*/
+ def foldLeft[B](z: B)(f: (B, A) => B): B = {
+ var acc = z
+ var these = this
+ while (!these.isEmpty) {
+ acc = f(acc, these.head)
+ these = these.tail
+ }
+ acc
+ }
+
+ override /*IterableLike*/
+ def foldRight[B](z: B)(f: (A, B) => B): B =
+ if (this.isEmpty) z
+ else f(head, tail.foldRight(z)(f))
+
+ override /*TraversableLike*/
+ def reduceLeft[B >: A](f: (B, A) => B): B =
+ if (isEmpty) throw new UnsupportedOperationException("empty.reduceLeft")
+ else tail.foldLeft[B](head)(f)
+
+ override /*IterableLike*/
+ def reduceRight[B >: A](op: (A, B) => B): B =
+ if (isEmpty) throw new UnsupportedOperationException("Nil.reduceRight")
+ else if (tail.isEmpty) head
+ else op(head, tail.reduceRight(op))
+
+ override /*TraversableLike*/
+ def last: A = {
+ if (isEmpty) throw new NoSuchElementException
+ var these = this
+ var nx = these.tail
+ while (!nx.isEmpty) {
+ these = nx
+ nx = nx.tail
+ }
+ these.head
+ }
+
+ override /*IterableLike*/
+ def take(n: Int): Repr = {
+ val b = newBuilder
+ var i = 0
+ var these = repr
+ while (!these.isEmpty && i < n) {
+ i += 1
+ b += these.head
+ these = these.tail
+ }
+ b.result
+ }
+
+ override /*TraversableLike*/
+ def drop(n: Int): Repr = {
+ var these: Repr = repr
+ var count = n
+ while (!these.isEmpty && count > 0) {
+ these = these.tail
+ count -= 1
+ }
+ these
+ }
+
+ override /*IterableLike*/
+ def dropRight(n: Int): Repr = {
+ val b = newBuilder
+ var these = this
+ var lead = this drop n
+ while (!lead.isEmpty) {
+ b += these.head
+ these = these.tail
+ lead = lead.tail
+ }
+ b.result
+ }
+
+ override /*IterableLike*/
+ def slice(from: Int, until: Int): Repr = {
+ val b = newBuilder
+ var i = from
+ var these = this drop from
+ while (i < until && !these.isEmpty) {
+ b += these.head
+ these = these.tail
+ i += 1
+ }
+ b.result
+ }
+
+ override /*IterableLike*/
+ def takeWhile(p: A => Boolean): Repr = {
+ val b = newBuilder
+ var these = this
+ while (!these.isEmpty && p(these.head)) {
+ b += these.head
+ these = these.tail
+ }
+ b.result
+ }
+
+ override /*TraversableLike*/
+ def span(p: A => Boolean): (Repr, Repr) = {
+ var these: Repr = repr
+ val b = newBuilder
+ while (!these.isEmpty && p(these.head)) {
+ b += these.head
+ these = these.tail
+ }
+ (b.result, these)
+ }
+
+ override /*IterableLike*/
+ def sameElements[B >: A](that: Iterable[B]): Boolean = that match {
+ case that1: LinearSeq[_] =>
+ var these = this
+ var those = that1
+ while (!these.isEmpty && !those.isEmpty && these.head == those.head) {
+ these = these.tail
+ those = those.tail
+ }
+ these.isEmpty && those.isEmpty
+ case _ =>
+ super.sameElements(that)
+ }
+
+ override /*SeqLike*/
+ def lengthCompare(len: Int): Int = {
+ var i = 0
+ var these = self
+ while (!these.isEmpty && i <= len) {
+ i += 1
+ these = these.tail
+ }
+ i - len
+ }
+
+ override /*SeqLike*/
+ def isDefinedAt(x: Int): Boolean = x >= 0 && lengthCompare(x) > 0
+
+ override /*SeqLike*/
+ def segmentLength(p: A => Boolean, from: Int): Int = {
+ var i = 0
+ var these = this drop from
+ while (!these.isEmpty && p(these.head)) {
+ i += 1
+ these = these.tail
+ }
+ i
+ }
+
+ override /*SeqLike*/
+ def indexWhere(p: A => Boolean, from: Int): Int = {
+ var i = from
+ var these = this drop from
+ while (these.nonEmpty) {
+ if (p(these.head))
+ return i
+
+ i += 1
+ these = these.tail
+ }
+ -1
+ }
+
+ override /*SeqLike*/
+ def lastIndexWhere(p: A => Boolean, end: Int): Int = {
+ var i = 0
+ var these = this
+ var last = -1
+ while (!these.isEmpty && i <= end) {
+ if (p(these.head)) last = i
+ these = these.tail
+ i += 1
+ }
+ last
+ }
+}
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index c8dae3fdfa..9dc102fb11 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -11,7 +11,7 @@
package scala.collection
-import mutable.{ListBuffer, HashMap, GenericArray}
+import mutable.{ListBuffer, HashMap, ArraySeq}
import immutable.{List, Range}
import generic._
@@ -801,7 +801,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self =>
* sorted according to the ordering `ord`.
*/
def sorted[B >: A](implicit ord: Ordering[B]): Repr = {
- val arr = new GenericArray[A](this.length)
+ val arr = new ArraySeq[A](this.length)
var i = 0
for (x <- this) {
arr(i) = x
diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala
index 6bf32dd71f..09e6a65158 100644
--- a/src/library/scala/collection/TraversableViewLike.scala
+++ b/src/library/scala/collection/TraversableViewLike.scala
@@ -53,6 +53,7 @@ self =>
*/
trait Transformed[+B] extends TraversableView[B, Coll] {
lazy val underlying = self.underlying
+ override def toString = stringPrefix+"(...)"
}
/** A fall back which forces everything into a vector and then applies an operation
diff --git a/src/library/scala/collection/generic/TraversableView.scala.1 b/src/library/scala/collection/generic/TraversableView.scala.1
deleted file mode 100644
index 3608de42be..0000000000
--- a/src/library/scala/collection/generic/TraversableView.scala.1
+++ /dev/null
@@ -1,152 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-package scalay.collection.generic
-
-import Math.MAX_INT
-import TraversableView.NoBuilder
-
-/** <p>
- * A base class for views of <code>Traversable</code>.
- * </p>
- * <p>
- * Every subclass has to implement the <code>foreach</code> method.
- * </p>
- *
- * @since 2.8
- */
-abstract class TraversableView[+A, +Coll <: Traversable[_]] extends Traversable[A] {
-self =>
-
- type This >: this.type <: TraversableView[A, Coll] { type This = self.This }
- protected val thisCollection: This = this
-
- protected[this] def newBuilder: Builder[A, This, This] =
- throw new UnsupportedOperationException(this+".newBuilder")
-
- def force[B >: A, That](implicit b: Builder[B, That, Coll]) = {
- b ++= this
- b.result()
- }
-
- trait Transformed[+B] extends TraversableView[B, Coll]
-
- /** pre: from >= 0
- */
- trait Sliced extends Transformed[A] {
- protected[this] val from: Int
- protected[this] val until: Int
- override def foreach(f: A => Unit) {
- var index = 0
- for (x <- self) {
- if (from <= index) {
- if (until <= index) return
- f(x)
- }
- index += 1
- }
- }
- override def stringPrefix = self.stringPrefix+"S"
- override def slice(from1: Int, until1: Int) =
- newSliced(from + (from1 max 0), from + (until1 max 0)).asInstanceOf[This]
- }
-
- trait Mapped[B] extends Transformed[B] {
- protected[this] val mapping: A => B
- override def foreach(f: B => Unit) {
- for (x <- self)
- f(mapping(x))
- }
- override def stringPrefix = self.stringPrefix+"M"
- }
-
- trait FlatMapped[B] extends Transformed[B] {
- protected[this] val mapping: A => Traversable[B]
- override def foreach(f: B => Unit) {
- for (x <- self)
- for (y <- mapping(x))
- f(y)
- }
- override def stringPrefix = self.stringPrefix+"N"
- }
-
- trait Appended[B >: A] extends Transformed[B] {
- protected[this] val rest: Traversable[B]
- override def foreach(f: B => Unit) {
- for (x <- self) f(x)
- for (x <- rest) f(x)
- }
- override def stringPrefix = self.stringPrefix+"A"
- }
-
- trait Filtered extends Transformed[A] {
- protected[this] val pred: A => Boolean
- override def foreach(f: A => Unit) {
- for (x <- self)
- if (pred(x)) f(x)
- }
- override def stringPrefix = self.stringPrefix+"F"
- }
-
- trait TakenWhile extends Transformed[A] {
- protected[this] val pred: A => Boolean
- override def foreach(f: A => Unit) {
- for (x <- self) {
- if (!pred(x)) return
- f(x)
- }
- }
- override def stringPrefix = self.stringPrefix+"T"
- }
-
- trait DroppedWhile extends Transformed[A] {
- protected[this] val pred: A => Boolean
- override def foreach(f: A => Unit) {
- var go = false
- for (x <- self) {
- if (!go && !pred(x)) go = true
- if (go) f(x)
- }
- }
- override def stringPrefix = self.stringPrefix+"D"
- }
-
- override def ++[B >: A, That](that: Traversable[B])(implicit b: Builder[B, That, This]): That =
- if (b.isInstanceOf[NoBuilder[_]]) newAppended(that).asInstanceOf[That]
- else super.++[B, That](that)(b)
-
- override def ++[B >: A, That](that: Iterator[B])(implicit b: Builder[B, That, This]): That = ++[B, That](that.toStream)
-
- override def map[B, That](f: A => B)(implicit b: Builder[B, That, This]): That =
- if (b.isInstanceOf[NoBuilder[_]]) newMapped(f).asInstanceOf[That]
- else super.map[B, That](f)(b)
-
- override def flatMap[B, That](f: A => Traversable[B])(implicit b: Builder[B, That, This]): That =
- if (b.isInstanceOf[NoBuilder[_]]) newFlatMapped(f).asInstanceOf[That]
- else super.flatMap[B, That](f)(b)
-
- override def filter(p: A => Boolean): This = newFiltered(p).asInstanceOf[This]
- override def init: This = newSliced(0, size - 1).asInstanceOf[This]
- override def drop(n: Int): This = newSliced(n max 0, MAX_INT).asInstanceOf[This]
- override def take(n: Int): This = newSliced(0, n).asInstanceOf[This]
- override def slice(from: Int, until: Int): This = newSliced(from max 0, until).asInstanceOf[This]
- override def dropWhile(p: A => Boolean): This = newDroppedWhile(p).asInstanceOf[This]
- override def takeWhile(p: A => Boolean): This = newTakenWhile(p).asInstanceOf[This]
- override def span(p: A => Boolean): (This, This) = (takeWhile(p), dropWhile(p))
- override def splitAt(n: Int): (This, This) = (take(n), drop(n))
-}
-
-object TraversableView {
- class NoBuilder[A] extends Builder[A, Nothing, TraversableView[_, _]] {
- def +=(elem: A) {}
- def iterator: Iterator[A] = Iterator.empty
- @deprecated("use `iterator' instead") def elements = iterator
- def result() = throw new UnsupportedOperationException("TraversableView.Builder.result")
- def clear() {}
- }
- implicit def implicitBuilder[A]: Builder[A, TraversableView[A, Traversable[_]], TraversableView[_, _]] = new NoBuilder
-}
diff --git a/src/library/scala/collection/immutable/IndexedSeq.scala b/src/library/scala/collection/immutable/IndexedSeq.scala
index 0d7b1b0d23..976ed61a65 100644
--- a/src/library/scala/collection/immutable/IndexedSeq.scala
+++ b/src/library/scala/collection/immutable/IndexedSeq.scala
@@ -14,8 +14,9 @@ package immutable
import generic._
import mutable.{ArrayBuffer, Builder}
-/** A subtrait of <code>collection.IndexedSeq</code> which represents sequences
+/** A subtrait of <code>collection.IndexedSeq</code> which represents indexed sequences
* that cannot be mutated.
+ * $indexedSeqInfo
*
* @since 2.8
*/
@@ -37,4 +38,4 @@ object IndexedSeq extends SeqFactory[IndexedSeq] {
}
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeq[A]] = new GenericCanBuildFrom[A]
def newBuilder[A]: Builder[A, IndexedSeq[A]] = new ArrayBuffer[A] mapResult (buf => new Impl(buf))
-} \ No newline at end of file
+}
diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala
index 52451e6012..6d72c0bb1a 100644
--- a/src/library/scala/collection/immutable/IntMap.scala
+++ b/src/library/scala/collection/immutable/IntMap.scala
@@ -151,7 +151,10 @@ import IntMap._
* <a href="http://citeseer.ist.psu.edu/okasaki98fast.html">Fast Mergeable Integer Maps</a>
* by Okasaki and Gill. Essentially a trie based on binary digits of the the integers.
*
+ * Note: This class is as of 2.8 largely superseded by HashMap.
+ *
* @since 2.7
+ *
*/
sealed abstract class IntMap[+T] extends Map[Int, T] with MapLike[Int, T, IntMap[T]] {
override def empty: IntMap[T] = IntMap.Nil;
diff --git a/src/library/scala/collection/immutable/LinearSeq.scala b/src/library/scala/collection/immutable/LinearSeq.scala
index c1efea037c..016afd4508 100644
--- a/src/library/scala/collection/immutable/LinearSeq.scala
+++ b/src/library/scala/collection/immutable/LinearSeq.scala
@@ -17,7 +17,7 @@ import mutable.Builder
/** A subtrait of <code>collection.LinearSeq</code> which represents sequences
* that cannot be mutated.
- *
+ * $linearSeqInfo
* @since 2.8
*/
trait LinearSeq[+A] extends Seq[A]
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala
index 3ccf6ee1ce..7522cc370f 100644
--- a/src/library/scala/collection/immutable/List.scala
+++ b/src/library/scala/collection/immutable/List.scala
@@ -46,7 +46,7 @@ import annotation.tailrec
sealed abstract class List[+A] extends LinearSeq[A]
with Product
with GenericTraversableTemplate[A, List]
- with LinearSeqLike[A, List[A]] {
+ with LinearSeqOptimized[A, List[A]] {
override def companion: GenericCompanion[List] = List
import scala.collection.{Iterable, Traversable, Seq, IndexedSeq}
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala
index e527712475..95ab40c5e2 100644
--- a/src/library/scala/collection/immutable/LongMap.scala
+++ b/src/library/scala/collection/immutable/LongMap.scala
@@ -138,6 +138,8 @@ import LongMap._;
* <a href="http://citeseer.ist.psu.edu/okasaki98fast.html">Fast Mergeable Long Maps</a>
* by Okasaki and Gill. Essentially a trie based on binary digits of the the integers.
*
+ * Note: This class is as of 2.8 largely superseded by HashMap.
+ *
* @since 2.7
*/
sealed abstract class LongMap[+T] extends Map[Long, T] with MapLike[Long, T, LongMap[T]] {
diff --git a/src/library/scala/collection/immutable/RedBlack.scala b/src/library/scala/collection/immutable/RedBlack.scala
index dfb34552cd..e7b4f3c978 100644
--- a/src/library/scala/collection/immutable/RedBlack.scala
+++ b/src/library/scala/collection/immutable/RedBlack.scala
@@ -12,7 +12,8 @@
package scala.collection
package immutable
-/**
+/** An base class containing the implementations for TreeMaps and TreeSets
+ *
* @since 2.3
*/
@serializable @SerialVersionUID(8691885935445612921L)
diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala
index afbf5d720e..640fb39af5 100644
--- a/src/library/scala/collection/immutable/Stack.scala
+++ b/src/library/scala/collection/immutable/Stack.scala
@@ -37,7 +37,7 @@ object Stack extends SeqFactory[Stack] {
@serializable @SerialVersionUID(1976480595012942526L)
class Stack[+A] protected (protected val elems: List[A]) extends LinearSeq[A]
with GenericTraversableTemplate[A, Stack]
- with LinearSeqLike[A, Stack[A]] {
+ with LinearSeqOptimized[A, Stack[A]] {
override def companion: GenericCompanion[Stack] = Stack
def this() = this(Nil)
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 39e6363e30..3b10963ddb 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -40,7 +40,7 @@ import scala.annotation.tailrec
*/
abstract class Stream[+A] extends LinearSeq[A]
with GenericTraversableTemplate[A, Stream]
- with LinearSeqLike[A, Stream[A]] {
+ with LinearSeqOptimized[A, Stream[A]] {
self =>
override def companion: GenericCompanion[Stream] = Stream
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index 5b70a0e785..5b5a627cfe 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -34,7 +34,7 @@ import StringLike._
/**
* @since 2.8
*/
-trait StringLike[+Repr] extends IndexedSeqLike[Char, Repr] with Ordered[String] {
+trait StringLike[+Repr] extends IndexedSeqOptimized[Char, Repr] with Ordered[String] {
self =>
/** Creates a string builder buffer as builder for this class */
diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala
index 0a46fc8a5d..85eb83ac1f 100644
--- a/src/library/scala/collection/mutable/ArrayBuffer.scala
+++ b/src/library/scala/collection/mutable/ArrayBuffer.scala
@@ -29,7 +29,7 @@ class ArrayBuffer[A](override protected val initialSize: Int)
extends Buffer[A]
with GenericTraversableTemplate[A, ArrayBuffer]
with BufferLike[A, ArrayBuffer[A]]
- with IndexedSeqLike[A, ArrayBuffer[A]]
+ with IndexedSeqOptimized[A, ArrayBuffer[A]]
with Builder[A, ArrayBuffer[A]]
with ResizableArray[A] {
diff --git a/src/library/scala/collection/mutable/ArrayLike.scala b/src/library/scala/collection/mutable/ArrayLike.scala
index c26f333afb..0b64f1255e 100644
--- a/src/library/scala/collection/mutable/ArrayLike.scala
+++ b/src/library/scala/collection/mutable/ArrayLike.scala
@@ -18,7 +18,7 @@ import generic._
*
* @since 2.8
*/
-trait ArrayLike[A, +Repr] extends IndexedSeqLike[A, Repr] { self =>
+trait ArrayLike[A, +Repr] extends IndexedSeqOptimized[A, Repr] { self =>
/** Creates a possible nested IndexedSeq which consists of all the elements
* of this array. If the elements are arrays themselves, the `deep' transformation
diff --git a/src/library/scala/collection/mutable/GenericArray.scala b/src/library/scala/collection/mutable/ArraySeq.scala
index 4aecf48585..f6f958601d 100644
--- a/src/library/scala/collection/mutable/GenericArray.scala
+++ b/src/library/scala/collection/mutable/ArraySeq.scala
@@ -22,12 +22,12 @@ import generic._
* @version 2.8
* @since 2.8
*/
-class GenericArray[A](override val length: Int)
+class ArraySeq[A](override val length: Int)
extends IndexedSeq[A]
- with GenericTraversableTemplate[A, GenericArray]
- with IndexedSeqLike[A, GenericArray[A]] {
+ with GenericTraversableTemplate[A, ArraySeq]
+ with IndexedSeqOptimized[A, ArraySeq[A]] {
- override def companion: GenericCompanion[GenericArray] = GenericArray
+ override def companion: GenericCompanion[ArraySeq] = ArraySeq
val array: Array[AnyRef] = new Array[AnyRef](length)
@@ -64,11 +64,11 @@ extends IndexedSeq[A]
}
}
-object GenericArray extends SeqFactory[GenericArray] {
- implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenericArray[A]] = new GenericCanBuildFrom[A]
- def newBuilder[A]: Builder[A, GenericArray[A]] =
+object ArraySeq extends SeqFactory[ArraySeq] {
+ implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArraySeq[A]] = new GenericCanBuildFrom[A]
+ def newBuilder[A]: Builder[A, ArraySeq[A]] =
new ArrayBuffer[A] mapResult { buf =>
- val result = new GenericArray[A](buf.length)
+ val result = new ArraySeq[A](buf.length)
buf.copyToArray(result.array.asInstanceOf[Array[Any]], 0)
result
}
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala
index 0e73bf7fad..b5094bc098 100644
--- a/src/library/scala/collection/mutable/FlatHashTable.scala
+++ b/src/library/scala/collection/mutable/FlatHashTable.scala
@@ -11,7 +11,7 @@
package scala.collection
package mutable
-/**
+/** An implementation class backing a HashSet.
* @since 2.3
*/
trait FlatHashTable[A] {
diff --git a/src/library/scala/collection/mutable/IndexedSeq.scala b/src/library/scala/collection/mutable/IndexedSeq.scala
index b11131e917..0a173395e0 100644
--- a/src/library/scala/collection/mutable/IndexedSeq.scala
+++ b/src/library/scala/collection/mutable/IndexedSeq.scala
@@ -16,6 +16,9 @@ import generic._
/** A subtrait of <code>collection.IndexedSeq</code> which represents sequences
* that can be mutated.
+ * $indexedSeqInfo
+ *
+ * @since 2.8
*/
trait IndexedSeq[A] extends Seq[A]
with scala.collection.IndexedSeq[A]
diff --git a/src/library/scala/collection/mutable/IndexedSeqOptimized.scala b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala
new file mode 100755
index 0000000000..134cc2a8ea
--- /dev/null
+++ b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala
@@ -0,0 +1,21 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: IndexedSeqLike.scala 20129 2009-12-14 17:12:17Z odersky $
+
+
+package scala.collection
+package mutable
+import generic._
+
+/** A subtrait of scala.collection.IndexedSeq which represents sequences
+ * that can be mutated.
+ *
+ * @since 2.8
+ */
+trait IndexedSeqOptimized[A, +Repr] extends IndexedSeqLike[A, Repr] with scala.collection.IndexedSeqOptimized[A, Repr]
diff --git a/src/library/scala/collection/mutable/IndexedSeqView.scala b/src/library/scala/collection/mutable/IndexedSeqView.scala
index e864845455..c6c92db1e7 100644
--- a/src/library/scala/collection/mutable/IndexedSeqView.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqView.scala
@@ -25,7 +25,10 @@ import TraversableView.NoBuilder
* @version 2.8
* @since 2.8
*/
-trait IndexedSeqView[A, +Coll] extends scala.collection.IndexedSeqView[A, Coll] {
+trait IndexedSeqView[A, +Coll] extends IndexedSeq[A]
+ with IndexedSeqOptimized[A, IndexedSeqView[A, Coll]]
+ with scala.collection.SeqView[A, Coll]
+ with scala.collection.SeqViewLike[A, Coll, IndexedSeqView[A, Coll]] {
self =>
def update(idx: Int, elem: A)
diff --git a/src/library/scala/collection/mutable/LinearSeq.scala b/src/library/scala/collection/mutable/LinearSeq.scala
index 04191e30bc..9abaef5aff 100644
--- a/src/library/scala/collection/mutable/LinearSeq.scala
+++ b/src/library/scala/collection/mutable/LinearSeq.scala
@@ -16,6 +16,7 @@ import generic._
/** A subtrait of <code>collection.LinearSeq</code> which represents sequences
* that can be mutated.
+ * $linearSeqInfo
*
* @since 2.8
*/
diff --git a/src/library/scala/collection/mutable/ListMap.scala b/src/library/scala/collection/mutable/ListMap.scala
index 82cc6340c0..c96873c81d 100644
--- a/src/library/scala/collection/mutable/ListMap.scala
+++ b/src/library/scala/collection/mutable/ListMap.scala
@@ -14,7 +14,7 @@ package mutable
import generic._
-/**
+/** A simple map backed by a list.
* @since 2.8
*/
@serializable
diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala
index e6423aa677..7784927c87 100644
--- a/src/library/scala/collection/mutable/MutableList.scala
+++ b/src/library/scala/collection/mutable/MutableList.scala
@@ -29,7 +29,7 @@ import immutable.{List, Nil}
*/
@serializable @SerialVersionUID(5938451523372603072L)
class MutableList[A] extends LinearSeq[A]
- with LinearSeqLike[A, MutableList[A]]
+ with LinearSeqOptimized[A, MutableList[A]]
with Builder[A, MutableList[A]] {
override protected[this] def newBuilder = new MutableList[A]
diff --git a/src/library/scala/collection/mutable/ResizableArray.scala b/src/library/scala/collection/mutable/ResizableArray.scala
index 435eb3ee0f..80ab1cd559 100644
--- a/src/library/scala/collection/mutable/ResizableArray.scala
+++ b/src/library/scala/collection/mutable/ResizableArray.scala
@@ -24,7 +24,7 @@ import generic._
*/
trait ResizableArray[A] extends IndexedSeq[A]
with GenericTraversableTemplate[A, ResizableArray]
- with IndexedSeqLike[A, ResizableArray[A]] {
+ with IndexedSeqOptimized[A, ResizableArray[A]] {
override def companion: GenericCompanion[ResizableArray] = ResizableArray
diff --git a/src/library/scala/math/Numeric.scala b/src/library/scala/math/Numeric.scala
index fc8e7c307d..65f213a08e 100644
--- a/src/library/scala/math/Numeric.scala
+++ b/src/library/scala/math/Numeric.scala
@@ -75,6 +75,21 @@ object Numeric {
}
implicit object ByteIsIntegral extends ByteIsIntegral with Ordering.ByteOrdering
+ trait CharIsIntegral extends Integral[Char] {
+ def plus(x: Char, y: Char): Char = (x + y).toChar
+ def minus(x: Char, y: Char): Char = (x - y).toChar
+ def times(x: Char, y: Char): Char = (x * y).toChar
+ def quot(x: Char, y: Char): Char = (x / y).toChar
+ def rem(x: Char, y: Char): Char = (x % y).toChar
+ def negate(x: Char): Char = (-x).toChar
+ def fromInt(x: Int): Char = x.toChar
+ def toInt(x: Char): Int = x.toInt
+ def toLong(x: Char): Long = x.toLong
+ def toFloat(x: Char): Float = x.toFloat
+ def toDouble(x: Char): Double = x.toDouble
+ }
+ implicit object CharIsIntegral extends CharIsIntegral with Ordering.CharOrdering
+
trait LongIsIntegral extends Integral[Long] {
def plus(x: Long, y: Long): Long = x + y
def minus(x: Long, y: Long): Long = x - y
diff --git a/src/library/scala/runtime/RichChar.scala b/src/library/scala/runtime/RichChar.scala
index 63fbe20f3c..f5e2625fd8 100644
--- a/src/library/scala/runtime/RichChar.scala
+++ b/src/library/scala/runtime/RichChar.scala
@@ -12,7 +12,7 @@
package scala.runtime
import java.lang.Character
-import collection.{IndexedSeq, IndexedSeqView}
+import collection.immutable.NumericRange
/** <p>
* For example, in the following code
@@ -82,22 +82,14 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] {
@deprecated("Use ch.isUpper instead")
def isUpperCase: Boolean = isUpper
- /** Create a <code>[Char]</code> over the characters from 'x' to 'y' - 1
+ /** Create a <code>[Char]</code> over the characters from 'x' to 'limit' - 1
*/
- def until(limit: Char): IndexedSeqView[Char, IndexedSeq[Char]] =
- if (limit <= x) IndexedSeq.empty.view
- else
- new IndexedSeqView[Char, IndexedSeq[Char]] {
- protected def underlying = IndexedSeq.empty[Char]
- def length = limit - x
- def apply(i: Int): Char = {
- require(i >= 0 && i < length)
- (x + i).toChar
- }
- }
-
- /** Create a <code>IndexedSeqView[Char]</code> over the characters from 'x' to 'y'
+ def until(limit: Char): NumericRange[Char] =
+ new NumericRange.Exclusive(x, limit, 1.toChar)
+
+ /** Create a <code>IndexedSeqView[Char]</code> over the characters from 'x' to 'limit'
*/
- def to(y: Char): IndexedSeqView[Char, IndexedSeq[Char]] = until((y + 1).toChar)
+ def to(limit: Char): NumericRange[Char] =
+ new NumericRange.Inclusive(x, limit, 1.toChar)
}
diff --git a/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala b/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala
index 6c75c748bb..34f52a1e19 100644
--- a/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala
+++ b/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala
@@ -82,7 +82,7 @@ class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) {
/** Repeats this rule num times */
def times(num : Int) : Rule[S, S, Seq[A], X] = from[S] {
- val result = new collection.mutable.GenericArray[A](num)
+ val result = new collection.mutable.ArraySeq[A](num)
// more compact using HoF but written this way so it's tail-recursive
def rep(i : Int, in : S) : Result[S, Seq[A], X] = {
if (i == num) Success(in, result)