summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPap Lőrinc <paplorinc@gmail.com>2016-12-06 23:01:12 +0200
committerPap Lőrinc <paplorinc@gmail.com>2016-12-07 13:38:02 +0200
commitbc912230129d68466474bcc6c99356b44f65c3c2 (patch)
tree02de5dd74e3240fff4dd7ecbc97223110d8f8a54
parent0339663cbbd4d22b0758257f2ce078b5a007f316 (diff)
downloadscala-bc912230129d68466474bcc6c99356b44f65c3c2.tar.gz
scala-bc912230129d68466474bcc6c99356b44f65c3c2.tar.bz2
scala-bc912230129d68466474bcc6c99356b44f65c3c2.zip
Changed hashing bit rotation to use Integer.rotateRight
-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 776eafaccc..445217ebef 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)
}
/**