diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-10-20 20:19:56 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-10-20 20:19:56 +0000 |
commit | d3d218e5ea77584489437f0dfa8148ee3764d6f7 (patch) | |
tree | 881fba9234da6654e8d914c8b56ddadd100c5cba /src/library/scala/collection/parallel/immutable/ParHashSet.scala | |
parent | d13a2529aa8218836d13ee04303da4f3325933c2 (diff) | |
download | scala-d3d218e5ea77584489437f0dfa8148ee3764d6f7.tar.gz scala-d3d218e5ea77584489437f0dfa8148ee3764d6f7.tar.bz2 scala-d3d218e5ea77584489437f0dfa8148ee3764d6f7.zip |
Further work on parallel mutable hash maps.
Changed HashTable interface.
Fixed one test.
Implemented hash map iterators.
Implementing hash map combiners.
Extracting common functionalities of bucket-based combiners.
No review.
Diffstat (limited to 'src/library/scala/collection/parallel/immutable/ParHashSet.scala')
-rw-r--r-- | src/library/scala/collection/parallel/immutable/ParHashSet.scala | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/src/library/scala/collection/parallel/immutable/ParHashSet.scala b/src/library/scala/collection/parallel/immutable/ParHashSet.scala index 0ef2681567..c9554ae1eb 100644 --- a/src/library/scala/collection/parallel/immutable/ParHashSet.scala +++ b/src/library/scala/collection/parallel/immutable/ParHashSet.scala @@ -11,6 +11,7 @@ import scala.collection.parallel.ParSetLike import scala.collection.parallel.Combiner import scala.collection.parallel.ParIterableIterator import scala.collection.parallel.EnvironmentPassingCombiner +import scala.collection.parallel.Unrolled import scala.collection.generic.ParSetFactory import scala.collection.generic.CanCombineFrom import scala.collection.generic.GenericParTemplate @@ -101,21 +102,13 @@ object ParHashSet extends ParSetFactory[ParHashSet] { } -private[immutable] trait HashSetCombiner[T] -extends Combiner[T, ParHashSet[T]] { +private[immutable] abstract class HashSetCombiner[T] +extends collection.parallel.BucketCombiner[T, ParHashSet[T], Any, HashSetCombiner[T]](HashSetCombiner.rootsize) { self: EnvironmentPassingCombiner[T, ParHashSet[T]] => import HashSetCombiner._ - var heads = new Array[Unrolled[Any]](rootsize) - var lasts = new Array[Unrolled[Any]](rootsize) - var size: Int = 0 - - def clear = { - heads = new Array[Unrolled[Any]](rootsize) - lasts = new Array[Unrolled[Any]](rootsize) - } def +=(elem: T) = { - size += 1 + sz += 1 val hc = elem.## val pos = hc & 0x1f if (lasts(pos) eq null) { @@ -128,25 +121,6 @@ self: EnvironmentPassingCombiner[T, ParHashSet[T]] => this } - def combine[N <: T, NewTo >: ParHashSet[T]](other: Combiner[N, NewTo]): Combiner[N, NewTo] = if (this ne other) { - if (other.isInstanceOf[HashSetCombiner[_]]) { - val that = other.asInstanceOf[HashSetCombiner[T]] - var i = 0 - while (i < rootsize) { - if (lasts(i) eq null) { - heads(i) = that.heads(i) - lasts(i) = that.lasts(i) - } else { - lasts(i).next = that.heads(i) - if (that.lasts(i) ne null) lasts(i) = that.lasts(i) - } - i += 1 - } - size = size + that.size - this - } else error("Unexpected combiner type.") - } else this - def result = { val buckets = heads.filter(_ != null) val root = new Array[HashSet[T]](buckets.length) @@ -171,7 +145,8 @@ self: EnvironmentPassingCombiner[T, ParHashSet[T]] => /* tasks */ - class CreateTrie(buckets: Array[Unrolled[Any]], root: Array[HashSet[T]], offset: Int, howmany: Int) extends super.Task[Unit, CreateTrie] { + class CreateTrie(buckets: Array[Unrolled[Any]], root: Array[HashSet[T]], offset: Int, howmany: Int) + extends super.Task[Unit, CreateTrie] { var result = () def leaf(prev: Option[Unit]) = { var i = offset @@ -274,6 +249,3 @@ object HashSetCombiner { - - - |