diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-06-10 08:58:07 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-06-10 08:58:07 +0000 |
commit | 5ad8adecf8a1df8e6ce008ba8b30d1f037346d49 (patch) | |
tree | 9872a1853f0f2ea59aa3c23c0e008f27d6fe3ea1 | |
parent | f8429e2fcd23ebfdb67203e86cf6002445c77a63 (diff) | |
download | scala-5ad8adecf8a1df8e6ce008ba8b30d1f037346d49.tar.gz scala-5ad8adecf8a1df8e6ce008ba8b30d1f037346d49.tar.bz2 scala-5ad8adecf8a1df8e6ce008ba8b30d1f037346d49.zip |
HashMap merge bug fixed. No review
-rw-r--r-- | src/library/scala/collection/immutable/HashMap.scala | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index 09620938ca..d731cd4352 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -372,16 +372,6 @@ time { mNew.iterator.foreach( p => ()) } println } - private def subtreeCount(bm: Int) = { - var c = 0 - var b = bm - while (b != 0) { - if ((b & 1) != 0) c += 1 - b = b >>> 1 - } - c - } - private def posOf(n: Int, bm: Int) = { var left = n var i = -1 @@ -398,9 +388,9 @@ time { mNew.iterator.foreach( p => ()) } // printBitmap(bitmap) // println(elems.toList) - // println("subtrees: " + subtreeCount(bitmap)) - // println("will split at: " + posOf(subtreeCount(bitmap) / 2, bitmap)) - val splitpoint = posOf(subtreeCount(bitmap) / 2, bitmap) + // println("subtrees: " + Integer.bitCount(bitmap)) + // println("will split at: " + posOf(Integer.bitCount(bitmap) / 2, bitmap)) + val splitpoint = posOf(Integer.bitCount(bitmap) / 2, bitmap) val bm1 = bitmap & (-1 << splitpoint) val bm2 = bitmap & (-1 >>> (32 - splitpoint)) // printBitmap(bm1) @@ -427,7 +417,7 @@ time { mNew.iterator.foreach( p => ()) } val bothbitmap = thisbm & thatbm // determine the necessary size for the array - val subcount = subtreeCount(combinedbitmap) + val subcount = Integer.bitCount(combinedbitmap) //printBitmap(combinedbitmap) //println(subcount) @@ -439,10 +429,9 @@ time { mNew.iterator.foreach( p => ()) } var i = 0 var thisi = 0 var thati = 0 - while (pos != 0) { + while (i < subcount) { if ((bothbitmap & pos) != 0) { combined(i) = thiselems(thisi) combine thatelems(thati) - dives += 1 i += 1 thisi += 1 thati += 1 @@ -459,7 +448,7 @@ time { mNew.iterator.foreach( p => ()) } } //println(combined.toList) - new HashTrieMap[A, B1](combinedbitmap, combined, this.size + that.size) + new HashTrieMap[A, B1](combinedbitmap, combined, combined.foldLeft(0)(_ + _.size)) case empty: HashMap[_, _] => this case _ => error("section supposed to be unreachable.") } |