summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-04-13 16:31:42 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-04-13 16:31:42 +0000
commit3de96153e5bfbde16dcc89bfbd71ff6e8cf1f6c6 (patch)
tree2794a7bd176b315a9f4bdc3f5ef5553254b7dd47 /test
parent9b5cb18dbd2d3e87def5da47ae76adb2e776487e (diff)
downloadscala-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')
-rw-r--r--test/disabled/scalacheck/HashTrieSplit.scala47
-rw-r--r--test/files/neg/t3774.check4
-rw-r--r--test/files/pos/spec-List.scala2
-rw-r--r--test/files/run/pc-conversions.scala8
-rw-r--r--test/files/scalacheck/HashTrieSplit.scala4
-rw-r--r--test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala6
-rw-r--r--test/files/scalacheck/parallel-collections/pc.scala10
7 files changed, 59 insertions, 22 deletions
diff --git a/test/disabled/scalacheck/HashTrieSplit.scala b/test/disabled/scalacheck/HashTrieSplit.scala
new file mode 100644
index 0000000000..6b20efe12b
--- /dev/null
+++ b/test/disabled/scalacheck/HashTrieSplit.scala
@@ -0,0 +1,47 @@
+
+
+
+
+
+import collection._
+
+
+
+
+// checks whether hash tries split their iterators correctly
+// even after some elements have been traversed
+object Test {
+ def main(args: Array[String]) {
+ doesSplitOk
+ }
+
+ def doesSplitOk = {
+ val sz = 2000
+ var ht = new parallel.immutable.ParHashMap[Int, Int]
+ // println("creating trie")
+ for (i <- 0 until sz) ht += ((i + sz, i))
+ // println("created trie")
+ for (n <- 0 until (sz - 1)) {
+ // println("---------> n = " + n)
+ val pit = ht.parallelIterator
+ val pit2 = ht.parallelIterator
+ var i = 0
+ while (i < n) {
+ pit.next
+ pit2.next
+ i += 1
+ }
+ // println("splitting")
+ val pits = pit.split
+ val fst = pits(0).toSet
+ val snd = pits(1).toSet
+ val orig = pit2.toSet
+ if (orig.size != (fst.size + snd.size) || orig != (fst ++ snd)) {
+ println("Original: " + orig)
+ println("First: " + fst)
+ println("Second: " + snd)
+ assert(false)
+ }
+ }
+ }
+}
diff --git a/test/files/neg/t3774.check b/test/files/neg/t3774.check
index 59c63c4ee8..a3953133bc 100644
--- a/test/files/neg/t3774.check
+++ b/test/files/neg/t3774.check
@@ -1,6 +1,6 @@
t3774.scala:4: error: overloaded method value ++ with alternatives:
- [B1 >: List[Int]](xs: scala.collection.TraversableOnce[((Int, Int), B1)])scala.collection.immutable.Map[(Int, Int),B1] <and>
- [B >: ((Int, Int), List[Int]),That](that: scala.collection.TraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Map[(Int, Int),List[Int]],B,That])That
+ [B1 >: List[Int]](xs: scala.collection.AnyTraversableOnce[((Int, Int), B1)])scala.collection.immutable.Map[(Int, Int),B1] <and>
+ [B >: ((Int, Int), List[Int]),That](that: scala.collection.AnyTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Map[(Int, Int),List[Int]],B,That])That
cannot be applied to (scala.collection.immutable.IndexedSeq[((Int, Int), scala.collection.immutable.Range.Inclusive)])
Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)})
^
diff --git a/test/files/pos/spec-List.scala b/test/files/pos/spec-List.scala
index e3055f3051..6a39632451 100644
--- a/test/files/pos/spec-List.scala
+++ b/test/files/pos/spec-List.scala
@@ -144,7 +144,7 @@ sealed trait List[@specialized +A] extends LinearSeq[A]
/** Create a new list which contains all elements of this list
* followed by all elements of Traversable `that'
*/
- override def ++[B >: A, That](xs: TraversableOnce[B])(implicit bf: CanBuildFrom[List[A], B, That]): That = {
+ override def ++[B >: A, That](xs: AnyTraversableOnce[B])(implicit bf: CanBuildFrom[List[A], B, That]): That = {
val b = bf(this)
if (b.isInstanceOf[ListBuffer[_]]) (this ::: xs.toList).asInstanceOf[That]
else super.++(xs)
diff --git a/test/files/run/pc-conversions.scala b/test/files/run/pc-conversions.scala
index 3121d82944..64e0720572 100644
--- a/test/files/run/pc-conversions.scala
+++ b/test/files/run/pc-conversions.scala
@@ -7,7 +7,7 @@ import collection._
object Test {
def main(args: Array[String]) {
- // disabled
+ testConversions
}
def testConversions {
@@ -53,9 +53,9 @@ object Test {
def assertSeq[T](pc: parallel.ParIterable[T]) = assert(pc.seq == pc)
- def assertPar[T, P <: Parallel](xs: Iterable[T]) = assert(xs == xs.par)
+ def assertPar[T, P <: Parallel](xs: AnyIterable[T]) = assert(xs == xs.par)
- def assertToPar[K, V](xs: Traversable[(K, V)]) {
+ def assertToPar[K, V](xs: AnyTraversable[(K, V)]) {
xs match {
case _: Seq[_] =>
assert(xs.toIterable.par == xs)
@@ -73,7 +73,7 @@ object Test {
assert(xs.par.toMap == xs.toMap)
}
- def assertToParWoMap[T](xs: Seq[T]) {
+ def assertToParWoMap[T](xs: AnySeq[T]) {
assert(xs.toIterable.par == xs.toIterable)
assert(xs.par.toIterable == xs.toIterable)
diff --git a/test/files/scalacheck/HashTrieSplit.scala b/test/files/scalacheck/HashTrieSplit.scala
index 6b20efe12b..e959a3d535 100644
--- a/test/files/scalacheck/HashTrieSplit.scala
+++ b/test/files/scalacheck/HashTrieSplit.scala
@@ -23,8 +23,8 @@ object Test {
// println("created trie")
for (n <- 0 until (sz - 1)) {
// println("---------> n = " + n)
- val pit = ht.parallelIterator
- val pit2 = ht.parallelIterator
+ val pit = ht.splitter
+ val pit2 = ht.splitter
var i = 0
while (i < n) {
pit.next
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
diff --git a/test/files/scalacheck/parallel-collections/pc.scala b/test/files/scalacheck/parallel-collections/pc.scala
index 4be7b0ec4d..103b5e2993 100644
--- a/test/files/scalacheck/parallel-collections/pc.scala
+++ b/test/files/scalacheck/parallel-collections/pc.scala
@@ -30,16 +30,6 @@ class ParCollProperties extends Properties("Parallel collections") {
// parallel vectors
include(immutable.IntParallelVectorCheck)
-
- /* Views */
-
- // parallel array views
-
- // parallel immutable hash map views
-
- // parallel mutable hash map views
-
- // parallel vector views
}