diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-04-13 16:31:42 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-04-13 16:31:42 +0000 |
commit | 3de96153e5bfbde16dcc89bfbd71ff6e8cf1f6c6 (patch) | |
tree | 2794a7bd176b315a9f4bdc3f5ef5553254b7dd47 /test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala | |
parent | 9b5cb18dbd2d3e87def5da47ae76adb2e776487e (diff) | |
download | scala-3de96153e5bfbde16dcc89bfbd71ff6e8cf1f6c6.tar.gz scala-3de96153e5bfbde16dcc89bfbd71ff6e8cf1f6c6.tar.bz2 scala-3de96153e5bfbde16dcc89bfbd71ff6e8cf1f6c6.zip |
Refactoring the collections api to support diff...
Refactoring the collections api to support differentiation between
referring to a sequential collection and a parallel collection, and to
support referring to both types of collections.
New set of traits Gen* are now superclasses of both their * and Par* subclasses. For example, GenIterable is a superclass of both Iterable and ParIterable. Iterable and ParIterable are not in a subclassing relation. The new class hierarchy is illustrated below (simplified, not all relations and classes are shown):
TraversableOnce --> GenTraversableOnce
^ ^
| |
Traversable --> GenTraversable
^ ^
| |
Iterable --> GenIterable <-- ParIterable
^ ^ ^
| | |
Seq --> GenSeq <-- ParSeq
(the *Like, *View and *ViewLike traits have a similar hierarchy)
General views extract common view functionality from parallel and
sequential collections.
This design also allows for more flexible extensions to the collections
framework. It also allows slowly factoring out common functionality up
into Gen* traits.
From now on, it is possible to write this:
import collection._
val p = parallel.ParSeq(1, 2, 3)
val g: GenSeq[Int] = p // meaning a General Sequence
val s = g.seq // type of s is Seq[Int]
for (elem <- g) {
// do something without guarantees on sequentiality of foreach
// this foreach may be executed in parallel
}
for (elem <- s) {
// do something with a guarantee that foreach is executed in order, sequentially
}
for (elem <- p) {
// do something concurrently, in parallel
}
This also means that some signatures had to be changed. For example,
method `flatMap` now takes `A => GenTraversableOnce[B]`, and `zip` takes
a `GenIterable[B]`.
Also, there are mutable & immutable Gen* trait variants. They have
generic companion functionality.
Diffstat (limited to 'test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala')
-rw-r--r-- | test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala index 744d22f05c..bdab66449d 100644 --- a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala @@ -71,11 +71,11 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col (inst, fromTraversable(inst), modif) } - def areEqual(t1: Traversable[T], t2: Traversable[T]) = if (hasStrictOrder) { + def areEqual(t1: AnyTraversable[T], t2: AnyTraversable[T]) = if (hasStrictOrder) { t1 == t2 && t2 == t1 } else (t1, t2) match { // it is slightly delicate what `equal` means if the order is not strict - case (m1: Map[_, _], m2: Map[_, _]) => m1 == m2 && m2 == m1 - case (i1: Iterable[_], i2: Iterable[_]) => + case (m1: AnyMap[_, _], m2: AnyMap[_, _]) => m1 == m2 && m2 == m1 + case (i1: AnyIterable[_], i2: AnyIterable[_]) => val i1s = i1.toSet val i2s = i2.toSet i1s == i2s && i2s == i1s |