diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-09-17 15:07:06 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-09-17 15:07:06 +0000 |
commit | ab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9 (patch) | |
tree | 87ac1715ce7f3f69b7e7af407c3a5479430ee348 /src/library/scala/collection/parallel/ParSeqLike.scala | |
parent | 94e9b95f9bb41797031efee71cfb349fce0a2261 (diff) | |
download | scala-ab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9.tar.gz scala-ab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9.tar.bz2 scala-ab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9.zip |
Refactorings to make iterators required by task...
Refactorings to make iterators required by task objects less restricted.
No review
Diffstat (limited to 'src/library/scala/collection/parallel/ParSeqLike.scala')
-rw-r--r-- | src/library/scala/collection/parallel/ParSeqLike.scala | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/library/scala/collection/parallel/ParSeqLike.scala b/src/library/scala/collection/parallel/ParSeqLike.scala index dcad5b4094..7e8b9d6129 100644 --- a/src/library/scala/collection/parallel/ParSeqLike.scala +++ b/src/library/scala/collection/parallel/ParSeqLike.scala @@ -41,7 +41,7 @@ extends scala.collection.SeqLike[T, Repr] with ParIterableLike[T, Repr, Sequential] { self => - type SuperParIterator = super.ParIterator + type SuperParIterator = ParIterableIterator[T] /** An iterator that can be split into arbitrary subsets of iterators. * The self-type requirement ensures that the signal context passing behaviour gets mixed in @@ -50,7 +50,7 @@ self => * '''Note:''' In concrete collection classes, collection implementers might want to override the iterator * `reverse2builder` method to ensure higher efficiency. */ - trait ParIterator extends ParSeqIterator[T, Repr] with super.ParIterator { + trait ParIterator extends ParSeqIterator[T] with super.ParIterator { me: SignalContextPassingIterator[ParIterator] => def split: Seq[ParIterator] def psplit(sizes: Int*): Seq[ParIterator] @@ -315,15 +315,15 @@ self => /* tasks */ - protected def down(p: SuperParIterator) = p.asInstanceOf[ParIterator] + protected[this] def down(p: ParIterableIterator[_]) = p.asInstanceOf[ParSeqIterator[T]] protected trait Accessor[R, Tp] extends super.Accessor[R, Tp] { - val pit: ParIterator + protected[this] val pit: ParSeqIterator[T] } protected trait Transformer[R, Tp] extends Accessor[R, Tp] with super.Transformer[R, Tp] - protected[this] class SegmentLength(pred: T => Boolean, from: Int, val pit: ParIterator) + protected[this] class SegmentLength(pred: T => Boolean, from: Int, protected[this] val pit: ParSeqIterator[T]) extends Accessor[(Int, Boolean), SegmentLength] { var result: (Int, Boolean) = null def leaf(prev: Option[(Int, Boolean)]) = if (from < pit.indexFlag) { @@ -332,7 +332,7 @@ self => result = (seglen, itsize == seglen) if (!result._2) pit.setIndexFlagIfLesser(from) } else result = (0, false) - def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException + protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException override def split = { val pits = pit.split for ((p, untilp) <- pits zip pits.scanLeft(0)(_ + _.remaining)) yield new SegmentLength(pred, from + untilp, p) @@ -340,7 +340,7 @@ self => override def merge(that: SegmentLength) = if (result._2) result = (result._1 + that.result._1, that.result._2) } - protected[this] class IndexWhere(pred: T => Boolean, from: Int, val pit: ParIterator) + protected[this] class IndexWhere(pred: T => Boolean, from: Int, protected[this] val pit: ParSeqIterator[T]) extends Accessor[Int, IndexWhere] { var result: Int = -1 def leaf(prev: Option[Int]) = if (from < pit.indexFlag) { @@ -350,7 +350,7 @@ self => pit.setIndexFlagIfLesser(from) } } - def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException + protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException override def split = { val pits = pit.split for ((p, untilp) <- pits zip pits.scanLeft(from)(_ + _.remaining)) yield new IndexWhere(pred, untilp, p) @@ -360,7 +360,7 @@ self => } } - protected[this] class LastIndexWhere(pred: T => Boolean, pos: Int, val pit: ParIterator) + protected[this] class LastIndexWhere(pred: T => Boolean, pos: Int, protected[this] val pit: ParSeqIterator[T]) extends Accessor[Int, LastIndexWhere] { var result: Int = -1 def leaf(prev: Option[Int]) = if (pos > pit.indexFlag) { @@ -370,7 +370,7 @@ self => pit.setIndexFlagIfGreater(pos) } } - def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException + protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException override def split = { val pits = pit.split for ((p, untilp) <- pits zip pits.scanLeft(pos)(_ + _.remaining)) yield new LastIndexWhere(pred, untilp, p) @@ -380,19 +380,19 @@ self => } } - protected[this] class Reverse[U >: T, This >: Repr](cbf: () => Combiner[U, This], val pit: ParIterator) + protected[this] class Reverse[U >: T, This >: Repr](cbf: () => Combiner[U, This], protected[this] val pit: ParSeqIterator[T]) extends Transformer[Combiner[U, This], Reverse[U, This]] { var result: Combiner[U, This] = null def leaf(prev: Option[Combiner[U, This]]) = result = pit.reverse2combiner(reuse(prev, cbf())) - def newSubtask(p: SuperParIterator) = new Reverse(cbf, down(p)) + protected[this] def newSubtask(p: SuperParIterator) = new Reverse(cbf, down(p)) override def merge(that: Reverse[U, This]) = result = that.result combine result } - protected[this] class ReverseMap[S, That](f: T => S, pbf: CanCombineFrom[Repr, S, That], val pit: ParIterator) + protected[this] class ReverseMap[S, That](f: T => S, pbf: CanCombineFrom[Repr, S, That], protected[this] val pit: ParSeqIterator[T]) extends Transformer[Combiner[S, That], ReverseMap[S, That]] { var result: Combiner[S, That] = null - def leaf(prev: Option[Combiner[S, That]]) = result = pit.reverseMap2combiner(f, pbf) // TODO - def newSubtask(p: SuperParIterator) = new ReverseMap(f, pbf, down(p)) + def leaf(prev: Option[Combiner[S, That]]) = result = pit.reverseMap2combiner(f, pbf(self.repr)) + protected[this] def newSubtask(p: SuperParIterator) = new ReverseMap(f, pbf, down(p)) override def merge(that: ReverseMap[S, That]) = result = that.result combine result } @@ -403,7 +403,7 @@ self => result = pit.sameElements(otherpit) if (!result) pit.abort } - def newSubtask(p: SuperParIterator) = unsupported + protected[this] def newSubtask(p: SuperParIterator) = unsupported override def split = { val fp = pit.remaining / 2 val sp = pit.remaining - fp @@ -412,11 +412,11 @@ self => override def merge(that: SameElements[U]) = result = result && that.result } - protected[this] class Updated[U >: T, That](pos: Int, elem: U, pbf: CanCombineFrom[Repr, U, That], val pit: ParIterator) + protected[this] class Updated[U >: T, That](pos: Int, elem: U, pbf: CanCombineFrom[Repr, U, That], protected[this] val pit: ParSeqIterator[T]) extends Transformer[Combiner[U, That], Updated[U, That]] { var result: Combiner[U, That] = null - def leaf(prev: Option[Combiner[U, That]]) = result = pit.updated2combiner(pos, elem, pbf) // TODO - def newSubtask(p: SuperParIterator) = unsupported + def leaf(prev: Option[Combiner[U, That]]) = result = pit.updated2combiner(pos, elem, pbf(self.repr)) + protected[this] def newSubtask(p: SuperParIterator) = unsupported override def split = { val pits = pit.split for ((p, untilp) <- pits zip pits.scanLeft(0)(_ + _.remaining)) yield new Updated(pos - untilp, elem, pbf, p) @@ -427,8 +427,8 @@ self => protected[this] class Zip[U >: T, S, That](len: Int, pbf: CanCombineFrom[Repr, (U, S), That], val pit: ParIterator, val otherpit: PreciseSplitter[S]) extends Transformer[Combiner[(U, S), That], Zip[U, S, That]] { var result: Result = null - def leaf(prev: Option[Result]) = result = pit.zip2combiner[U, S, That](otherpit)(pbf) - def newSubtask(p: SuperParIterator) = unsupported + def leaf(prev: Option[Result]) = result = pit.zip2combiner[U, S, That](otherpit, pbf(self.repr)) + protected[this] def newSubtask(p: SuperParIterator) = unsupported override def split = { val fp = len / 2 val sp = len - len / 2 @@ -449,7 +449,7 @@ self => result = pit.corresponds(corr)(otherpit) if (!result) pit.abort } - def newSubtask(p: SuperParIterator) = unsupported + protected[this] def newSubtask(p: SuperParIterator) = unsupported override def split = { val fp = pit.remaining / 2 val sp = pit.remaining - fp |