diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-11 14:38:29 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-11 14:38:29 +0000 |
commit | a1fd391c10e9b71ca2850cdcde3c76f6ec9d6c78 (patch) | |
tree | a222ce73539c7c2baf528debbe19a04b0b3d1abf /src | |
parent | 2d4a8afdc3c0a761aa569080ec368600cdfc794f (diff) | |
download | scala-a1fd391c10e9b71ca2850cdcde3c76f6ec9d6c78.tar.gz scala-a1fd391c10e9b71ca2850cdcde3c76f6ec9d6c78.tar.bz2 scala-a1fd391c10e9b71ca2850cdcde3c76f6ec9d6c78.zip |
Solved a performance problem in parallel hash t...
Solved a performance problem in parallel hash table sets.
No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala | 8 | ||||
-rw-r--r-- | src/library/scala/collection/parallel/mutable/ParHashSet.scala | 30 |
2 files changed, 26 insertions, 12 deletions
diff --git a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala index f52bfc8544..fc63d51b33 100644 --- a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala +++ b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala @@ -23,7 +23,13 @@ trait ParFlatHashTable[T] extends collection.mutable.FlatHashTable[T] { if (hasNext) scan() private def scan() { - while (itertable(idx) eq null) idx += 1 + while (itertable(idx) eq null) { + idx += 1 + } + } + + private def checkbounds = if (idx >= itertable.length) { + throw new IndexOutOfBoundsException(idx.toString) } def newIterator(index: Int, until: Int, totalsize: Int): ParIterableIterator[T] diff --git a/src/library/scala/collection/parallel/mutable/ParHashSet.scala b/src/library/scala/collection/parallel/mutable/ParHashSet.scala index 5386ae278d..9c505f6920 100644 --- a/src/library/scala/collection/parallel/mutable/ParHashSet.scala +++ b/src/library/scala/collection/parallel/mutable/ParHashSet.scala @@ -174,17 +174,25 @@ self: EnvironmentPassingCombiner[T, ParHashSet[T]] => */ def insertEntry(insertAt: Int, comesBefore: Int, elem: T): Int = { var h = insertAt - // if (h == -1) h = index(elemHashCode(elem)) - // var entry = table(h) - // while (null != entry) { - // if (entry == elem) return 0 - // h = (h + 1) // we *do not* do `(h + 1) % table.length` here, because we don't overlap!! - // if (h >= comesBefore) return -1 - // entry = table(h) - // } - // table(h) = elem.asInstanceOf[AnyRef] - // tableSize = tableSize + 1 - // nnSizeMapAdd(h) + if (h == -1) h = index(elemHashCode(elem)) + var entry = table(h) + while (null != entry) { + if (entry == elem) return 0 + h = h + 1 // we *do not* do `(h + 1) % table.length` here, because we'll never overflow!! + if (h >= comesBefore) return -1 + entry = table(h) + } + table(h) = elem.asInstanceOf[AnyRef] + + // this is incorrect since we set size afterwards anyway and such a + // counter would not work anyway: + // + // tableSize = tableSize + 1 + // + // interestingly, it completely bogs down the parallel + // execution when there are multiple workers + + nnSizeMapAdd(h) 1 } } |