summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPap LÅ‘rinc <paplorinc@gmail.com>2016-12-06 23:01:12 +0200
committerAdriaan Moors <adriaan@lightbend.com>2017-01-05 13:27:05 -0800
commit276db03285e25e54acbe004070ea9853193ab73f (patch)
treee3a598bf3a62fea5771462e772b3d27ed51151bf /src
parent26ad9cc73c88bad0140adb7cec583a4d05db498d (diff)
downloadscala-276db03285e25e54acbe004070ea9853193ab73f.tar.gz
scala-276db03285e25e54acbe004070ea9853193ab73f.tar.bz2
scala-276db03285e25e54acbe004070ea9853193ab73f.zip
Changed hashing bit rotation to use Integer.rotateRight
(cherry picked from commit bc912230129d68466474bcc6c99356b44f65c3c2)
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/mutable/FlatHashTable.scala18
-rw-r--r--src/library/scala/collection/mutable/HashTable.scala9
2 files changed, 8 insertions, 19 deletions
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala
index 25cc873b82..8c4115b1dd 100644
--- a/src/library/scala/collection/mutable/FlatHashTable.scala
+++ b/src/library/scala/collection/mutable/FlatHashTable.scala
@@ -10,6 +10,9 @@ package scala
package collection
package mutable
+import java.lang.Integer.rotateRight
+import scala.util.hashing.byteswap32
+
/** An implementation class backing a `HashSet`.
*
* This trait is used internally. It can be mixed in with various collections relying on
@@ -415,20 +418,7 @@ private[collection] object FlatHashTable {
// so that:
protected final def sizeMapBucketSize = 1 << sizeMapBucketBitSize
- protected final def improve(hcode: Int, seed: Int) = {
- //var h: Int = hcode + ~(hcode << 9)
- //h = h ^ (h >>> 14)
- //h = h + (h << 4)
- //h ^ (h >>> 10)
-
- val improved= scala.util.hashing.byteswap32(hcode)
-
- // for the remainder, see SI-5293
- // to ensure that different bits are used for different hash tables, we have to rotate based on the seed
- val rotation = seed % 32
- val rotated = (improved >>> rotation) | (improved << (32 - rotation))
- rotated
- }
+ protected final def improve(hcode: Int, seed: Int) = rotateRight(byteswap32(hcode), seed)
/**
* Elems have type A, but we store AnyRef in the table. Plus we need to deal with
diff --git a/src/library/scala/collection/mutable/HashTable.scala b/src/library/scala/collection/mutable/HashTable.scala
index dd08e3d9fb..9364344ca5 100644
--- a/src/library/scala/collection/mutable/HashTable.scala
+++ b/src/library/scala/collection/mutable/HashTable.scala
@@ -12,6 +12,9 @@ package scala
package collection
package mutable
+import java.lang.Integer.rotateRight
+import scala.util.hashing.byteswap32
+
/** This class can be used to construct data structures that are based
* on hashtables. Class `HashTable[A]` implements a hashtable
* that maps keys of type `A` to values of the fully abstract
@@ -424,11 +427,7 @@ private[collection] object HashTable {
* }}}
* the rest of the computation is due to SI-5293
*/
- protected final def improve(hcode: Int, seed: Int): Int = {
- val hash = scala.util.hashing.byteswap32(hcode)
- val shift = seed & ((1 << 5) - 1)
- (hash >>> shift) | (hash << (32 - shift))
- }
+ protected final def improve(hcode: Int, seed: Int): Int = rotateRight(byteswap32(hcode), seed)
}
/**