File tree Expand file tree Collapse file tree 2 files changed +8
-19
lines changed
src/library/scala/collection/mutable Expand file tree Collapse file tree 2 files changed +8
-19
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ package scala
10
10
package collection
11
11
package mutable
12
12
13
+ import java .lang .Integer .rotateRight
14
+ import scala .util .hashing .byteswap32
15
+
13
16
/** An implementation class backing a `HashSet`.
14
17
*
15
18
* This trait is used internally. It can be mixed in with various collections relying on
@@ -415,20 +418,7 @@ private[collection] object FlatHashTable {
415
418
// so that:
416
419
protected final def sizeMapBucketSize = 1 << sizeMapBucketBitSize
417
420
418
- protected final def improve (hcode : Int , seed : Int ) = {
419
- // var h: Int = hcode + ~(hcode << 9)
420
- // h = h ^ (h >>> 14)
421
- // h = h + (h << 4)
422
- // h ^ (h >>> 10)
423
-
424
- val improved = scala.util.hashing.byteswap32(hcode)
425
-
426
- // for the remainder, see SI-5293
427
- // to ensure that different bits are used for different hash tables, we have to rotate based on the seed
428
- val rotation = seed % 32
429
- val rotated = (improved >>> rotation) | (improved << (32 - rotation))
430
- rotated
431
- }
421
+ protected final def improve (hcode : Int , seed : Int ) = rotateRight(byteswap32(hcode), seed)
432
422
433
423
/**
434
424
* Elems have type A, but we store AnyRef in the table. Plus we need to deal with
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ package scala
12
12
package collection
13
13
package mutable
14
14
15
+ import java .lang .Integer .rotateRight
16
+ import scala .util .hashing .byteswap32
17
+
15
18
/** This class can be used to construct data structures that are based
16
19
* on hashtables. Class `HashTable[A]` implements a hashtable
17
20
* that maps keys of type `A` to values of the fully abstract
@@ -424,11 +427,7 @@ private[collection] object HashTable {
424
427
* }}}
425
428
* the rest of the computation is due to SI-5293
426
429
*/
427
- protected final def improve (hcode : Int , seed : Int ): Int = {
428
- val hash = scala.util.hashing.byteswap32(hcode)
429
- val shift = seed & ((1 << 5 ) - 1 )
430
- (hash >>> shift) | (hash << (32 - shift))
431
- }
430
+ protected final def improve (hcode : Int , seed : Int ): Int = rotateRight(byteswap32(hcode), seed)
432
431
}
433
432
434
433
/**
You can’t perform that action at this time.
0 commit comments