diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-12 14:58:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 14:58:10 +0100 |
commit | 623f0a72bad9513a154b4a6367c5e215adf769d0 (patch) | |
tree | f0b1493d0e30a84618026dd9700b66978f9f343d /src/library | |
parent | 84484df5b990d69b2a94209e32e330f5b05f8f20 (diff) | |
parent | bc912230129d68466474bcc6c99356b44f65c3c2 (diff) | |
download | scala-623f0a72bad9513a154b4a6367c5e215adf769d0.tar.gz scala-623f0a72bad9513a154b4a6367c5e215adf769d0.tar.bz2 scala-623f0a72bad9513a154b4a6367c5e215adf769d0.zip |
Merge pull request #5569 from paplorinc/rotr
Changed hashing bit rotation to use Integer.rotateRight
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/mutable/FlatHashTable.scala | 18 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/HashTable.scala | 9 |
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) } /** |