summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-09 22:24:53 +0000
committerPaul Phillips <paulp@improving.org>2011-08-09 22:24:53 +0000
commit333f540595b5cc80879758f656cccd99632d3fd5 (patch)
treeca2fb4419a433c7af3755e2faa384ae3d3c7bf4c /src
parent87aca406769cf3c90f375fcf03d9b47725591650 (diff)
downloadscala-333f540595b5cc80879758f656cccd99632d3fd5.tar.gz
scala-333f540595b5cc80879758f656cccd99632d3fd5.tar.bz2
scala-333f540595b5cc80879758f656cccd99632d3fd5.zip
Moved the classes and objects which are defined...
Moved the classes and objects which are defined in package objects out. In principle this is something you should be able to do. In practice right now it means bugs, to no advantage. I also deprecated RangeUtils, an unused, undocumented trait in the immutable package. It seems like there is a ton of stuff in the public API which should not be in the public API. It's really tedious having to go through a whole deprecation cycle to dispose of what could have been an internal-only class (and was presumably intended as such given the the absence of documentation.) No review.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/immutable/package.scala98
-rw-r--r--src/library/scala/collection/package.scala8
-rw-r--r--src/library/scala/collection/parallel/immutable/package.scala22
-rw-r--r--src/library/scala/collection/parallel/mutable/package.scala19
-rw-r--r--src/library/scala/collection/parallel/package.scala137
5 files changed, 141 insertions, 143 deletions
diff --git a/src/library/scala/collection/immutable/package.scala b/src/library/scala/collection/immutable/package.scala
index 5ff9fa223d..eec5f04fff 100644
--- a/src/library/scala/collection/immutable/package.scala
+++ b/src/library/scala/collection/immutable/package.scala
@@ -1,17 +1,21 @@
-package scala.collection
-
-
-
-
-
-
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+package scala.collection
-
-package object immutable {
-
+package immutable {
+ /** It looks like once upon a time this was used by ParRange, but
+ * since December 2010 in r23721 it is not used by anything. We
+ * should not have public API traits with seductive names like
+ * "RangeUtils" which are neither documented nor used.
+ */
+ @deprecated("this class will be removed", "2.10.0")
trait RangeUtils[+Repr <: RangeUtils[Repr]] {
-
def start: Int
def end: Int
def step: Int
@@ -23,16 +27,17 @@ package object immutable {
(size / step.toLong * step.toLong + start.toLong).toInt
}
- final def _last: Int = if (!inclusive) {
- if (step == 1 || step == -1) end - step
- else {
- val inclast = inclusiveLast
- if ((end.toLong - start.toLong) % step == 0) inclast - step else inclast
+ final def _last: Int = (
+ if (!inclusive) {
+ if (step == 1 || step == -1) end - step
+ else {
+ val inclast = inclusiveLast
+ if ((end.toLong - start.toLong) % step == 0) inclast - step else inclast
+ }
}
- } else {
- if (step == 1 || step == -1) end
+ else if (step == 1 || step == -1) end
else inclusiveLast
- }
+ )
final def _foreach[U](f: Int => U) = if (_length > 0) {
var i = start
@@ -43,39 +48,46 @@ package object immutable {
}
}
- final def _length: Int = if (!inclusive) {
- if (end > start == step > 0 && start != end) {
- (_last.toLong - start.toLong) / step.toLong + 1
- } else 0
- }.toInt else {
- if (end > start == step > 0 || start == end) {
- (_last.toLong - start.toLong) / step.toLong + 1
- } else 0
- }.toInt
+ final def _length: Int = (
+ if (!inclusive) {
+ if (end > start == step > 0 && start != end) {
+ (_last.toLong - start.toLong) / step.toLong + 1
+ } else 0
+ }.toInt
+ else {
+ if (end > start == step > 0 || start == end) {
+ (_last.toLong - start.toLong) / step.toLong + 1
+ } else 0
+ }.toInt
+ )
final def _apply(idx: Int): Int = {
if (idx < 0 || idx >= _length) throw new IndexOutOfBoundsException(idx.toString)
start + idx * step
}
- private def locationAfterN(n: Int) = if (n > 0) {
- if (step > 0) ((start.toLong + step.toLong * n.toLong) min _last.toLong).toInt
- else ((start.toLong + step.toLong * n.toLong) max _last.toLong).toInt
- } else start
-
- final def _take(n: Int) = if (n > 0 && _length > 0) {
- create(start, locationAfterN(n), step, true)
- } else create(start, start, step, false)
+ private def locationAfterN(n: Int) = (
+ if (n > 0) {
+ if (step > 0)
+ math.min(start.toLong + step.toLong * n.toLong, _last.toLong).toInt
+ else
+ math.max(start.toLong + step.toLong * n.toLong, _last.toLong).toInt
+ }
+ else start
+ )
- final def _drop(n: Int) = create(locationAfterN(n), end, step, inclusive)
+ final def _take(n: Int) = (
+ if (n > 0 && _length > 0)
+ create(start, locationAfterN(n), step, true)
+ else
+ create(start, start, step, false)
+ )
+ final def _drop(n: Int) = create(locationAfterN(n), end, step, inclusive)
final def _slice(from: Int, until: Int) = _drop(from)._take(until - from)
-
}
-
}
-
-
-
-
+package object immutable {
+ /** Nothing left after I promoted RangeUtils to the package. */
+}
diff --git a/src/library/scala/collection/package.scala b/src/library/scala/collection/package.scala
index f0a0c40bcd..0dd4405cf7 100644
--- a/src/library/scala/collection/package.scala
+++ b/src/library/scala/collection/package.scala
@@ -1,3 +1,11 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
package scala
/**
diff --git a/src/library/scala/collection/parallel/immutable/package.scala b/src/library/scala/collection/parallel/immutable/package.scala
index 19f8665667..7b1e39d092 100644
--- a/src/library/scala/collection/parallel/immutable/package.scala
+++ b/src/library/scala/collection/parallel/immutable/package.scala
@@ -8,15 +8,7 @@
package scala.collection.parallel
-package object immutable {
-
- /* package level methods */
- def repetition[T](elem: T, len: Int) = new Repetition(elem, len)
-
- /* constants */
-
- /* classes */
-
+package immutable {
/** A (parallel) sequence consisting of `length` elements `elem`. Used in the `padTo` method.
*
* @tparam T type of the elements
@@ -24,7 +16,8 @@ package object immutable {
* @param length the length of the collection
*/
private[parallel] class Repetition[T](elem: T, val length: Int) extends ParSeq[T] {
- self =>
+ self =>
+
def apply(idx: Int) = if (0 <= idx && idx < length) elem else throw new IndexOutOfBoundsException("" + idx)
override def seq = throw new UnsupportedOperationException
def update(idx: Int, elem: T) = throw new UnsupportedOperationException
@@ -32,7 +25,8 @@ package object immutable {
type SCPI = SignalContextPassingIterator[ParIterator]
class ParIterator(var i: Int = 0, val until: Int = length, elem: T = self.elem) extends super.ParIterator {
- me: SignalContextPassingIterator[ParIterator] =>
+ me: SignalContextPassingIterator[ParIterator] =>
+
def remaining = until - i
def hasNext = i < until
def next = { i += 1; elem }
@@ -45,6 +39,10 @@ package object immutable {
}
def splitter = new ParIterator with SCPI
-
}
}
+
+package object immutable {
+ /* package level methods */
+ def repetition[T](elem: T, len: Int) = new Repetition(elem, len)
+}
diff --git a/src/library/scala/collection/parallel/mutable/package.scala b/src/library/scala/collection/parallel/mutable/package.scala
index 1efe79b00d..28c5a2e732 100644
--- a/src/library/scala/collection/parallel/mutable/package.scala
+++ b/src/library/scala/collection/parallel/mutable/package.scala
@@ -1,22 +1,25 @@
-package scala.collection.parallel
-
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+package scala.collection.parallel
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArraySeq
import scala.collection.generic.Sizing
-
-
package object mutable {
-
/* aliases */
-
type ParArrayCombiner[T] = ResizableParArrayCombiner[T]
val ParArrayCombiner = ResizableParArrayCombiner
+}
+package mutable {
/* classes and traits */
-
private[mutable] trait SizeMapUtils {
protected def calcNumElems(from: Int, until: Int, tableLength: Int, sizeMapBucketSize: Int) = {
@@ -53,7 +56,6 @@ package object mutable {
}
/* hack-arounds */
-
private[mutable] class ExposedArrayBuffer[T] extends ArrayBuffer[T] with Sizing {
def internalArray = array
def setInternalSize(s: Int) = size0 = s
@@ -71,5 +73,4 @@ package object mutable {
override val length = sz
override def stringPrefix = "ArraySeq"
}
-
}
diff --git a/src/library/scala/collection/parallel/package.scala b/src/library/scala/collection/parallel/package.scala
index 7c83d43487..e22d34b4c2 100644
--- a/src/library/scala/collection/parallel/package.scala
+++ b/src/library/scala/collection/parallel/package.scala
@@ -6,23 +6,17 @@
** |/ **
\* */
-
package scala.collection
-
-import java.lang.Thread._
-
import scala.collection.generic.CanBuildFrom
import scala.collection.generic.CanCombineFrom
import scala.collection.parallel.mutable.ParArray
import scala.collection.mutable.UnrolledBuffer
import annotation.unchecked.uncheckedVariance
-
/** Package object for parallel collections.
*/
package object parallel {
-
/* constants */
val MIN_FOR_COPY = 512
val CHECK_RATE = 512
@@ -56,16 +50,6 @@ package object parallel {
/* implicit conversions */
- trait FactoryOps[From, Elem, To] {
- trait Otherwise[R] {
- def otherwise(notbody: => R): R
- }
-
- def isParallel: Boolean
- def asParallel: CanCombineFrom[From, Elem, To]
- def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R): Otherwise[R]
- }
-
implicit def factory2ops[From, Elem, To](bf: CanBuildFrom[From, Elem, To]) = new FactoryOps[From, Elem, To] {
def isParallel = bf.isInstanceOf[Parallel]
def asParallel = bf.asInstanceOf[CanCombineFrom[From, Elem, To]]
@@ -73,21 +57,6 @@ package object parallel {
def otherwise(notbody: => R) = if (isParallel) isbody(asParallel) else notbody
}
}
-
- trait TraversableOps[T] {
- trait Otherwise[R] {
- def otherwise(notbody: => R): R
- }
-
- def isParallel: Boolean
- def isParIterable: Boolean
- def asParIterable: ParIterable[T]
- def isParSeq: Boolean
- def asParSeq: ParSeq[T]
- def ifParSeq[R](isbody: ParSeq[T] => R): Otherwise[R]
- def toParArray: ParArray[T]
- }
-
implicit def traversable2ops[T](t: collection.GenTraversableOnce[T]) = new TraversableOps[T] {
def isParallel = t.isInstanceOf[Parallel]
def isParIterable = t.isInstanceOf[ParIterable[_]]
@@ -104,11 +73,6 @@ package object parallel {
cb.result
}
}
-
- trait ThrowableOps {
- def alongWith(that: Throwable): Throwable
- }
-
implicit def throwable2ops(self: Throwable) = new ThrowableOps {
def alongWith(that: Throwable) = (self, that) match {
case (self: CompositeThrowable, that: CompositeThrowable) => new CompositeThrowable(self.throwables ++ that.throwables)
@@ -117,14 +81,46 @@ package object parallel {
case _ => new CompositeThrowable(Set(self, that))
}
}
+}
+
+package parallel {
+ trait FactoryOps[From, Elem, To] {
+ trait Otherwise[R] {
+ def otherwise(notbody: => R): R
+ }
+
+ def isParallel: Boolean
+ def asParallel: CanCombineFrom[From, Elem, To]
+ def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R): Otherwise[R]
+ }
+
+ trait TraversableOps[T] {
+ trait Otherwise[R] {
+ def otherwise(notbody: => R): R
+ }
+
+ def isParallel: Boolean
+ def isParIterable: Boolean
+ def asParIterable: ParIterable[T]
+ def isParSeq: Boolean
+ def asParSeq: ParSeq[T]
+ def ifParSeq[R](isbody: ParSeq[T] => R): Otherwise[R]
+ def toParArray: ParArray[T]
+ }
+
+ trait ThrowableOps {
+ def alongWith(that: Throwable): Throwable
+ }
/* classes */
/** Composite throwable - thrown when multiple exceptions are thrown at the same time. */
- final case class CompositeThrowable(val throwables: Set[Throwable])
- extends Throwable("Multiple exceptions thrown during a parallel computation: " + throwables.map(
- t => t + "\n" + t.getStackTrace.take(10).++("...").mkString("\n")
- ).mkString("\n\n"))
+ final case class CompositeThrowable(
+ val throwables: Set[Throwable]
+ ) extends Throwable(
+ "Multiple exceptions thrown during a parallel computation: " +
+ throwables.map(t => t + "\n" + t.getStackTrace.take(10).++("...").mkString("\n")).mkString("\n\n")
+ )
/** A helper iterator for iterating very small array buffers.
@@ -202,45 +198,28 @@ package object parallel {
def beforeCombine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]) {}
def afterCombine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]) {}
- def combine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]): Combiner[N, NewTo] = if (this ne other) {
- if (other.isInstanceOf[BucketCombiner[_, _, _, _]]) {
- beforeCombine(other)
-
- val that = other.asInstanceOf[BucketCombiner[Elem, To, Buck, CombinerType]]
- var i = 0
- while (i < bucketnumber) {
- if (buckets(i) eq null) {
- buckets(i) = that.buckets(i)
- } else {
- if (that.buckets(i) ne null) buckets(i) concat that.buckets(i)
+ def combine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]): Combiner[N, NewTo] = {
+ if (this eq other) this
+ else other match {
+ case _: BucketCombiner[_, _, _, _] =>
+ beforeCombine(other)
+ val that = other.asInstanceOf[BucketCombiner[Elem, To, Buck, CombinerType]]
+
+ var i = 0
+ while (i < bucketnumber) {
+ if (buckets(i) eq null)
+ buckets(i) = that.buckets(i)
+ else if (that.buckets(i) ne null)
+ buckets(i) concat that.buckets(i)
+
+ i += 1
}
- i += 1
- }
- sz = sz + that.size
-
- afterCombine(other)
-
- this
- } else sys.error("Unexpected combiner type.")
- } else this
-
+ sz = sz + that.size
+ afterCombine(other)
+ this
+ case _ =>
+ sys.error("Unexpected combiner type.")
+ }
+ }
}
-
-
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-