File tree Expand file tree Collapse file tree 3 files changed +4
-17
lines changed
src/library/scala/collection/mutable Expand file tree Collapse file tree 3 files changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,7 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] {
47
47
48
48
@ transient protected var seedvalue : Int = tableSizeSeed
49
49
50
- import HashTable .powerOfTwo
51
-
52
- protected def capacity (expectedSize : Int ) = if (expectedSize == 0 ) 1 else powerOfTwo(expectedSize)
50
+ protected def capacity (expectedSize : Int ) = HashTable .nextPositivePowerOfTwo(expectedSize)
53
51
54
52
/** The initial size of the hash table.
55
53
*/
Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ private[collection] object HashTable {
401
401
402
402
private [collection] final def sizeForThreshold (_loadFactor : Int , thr : Int ) = ((thr.toLong * loadFactorDenum) / _loadFactor).toInt
403
403
404
- private [collection] final def capacity (expectedSize : Int ) = if (expectedSize == 0 ) 1 else powerOfTwo (expectedSize)
404
+ private [collection] final def capacity (expectedSize : Int ) = nextPositivePowerOfTwo (expectedSize)
405
405
406
406
trait HashUtils [KeyType ] {
407
407
protected final def sizeMapBucketBitSize = 5
@@ -429,16 +429,7 @@ private[collection] object HashTable {
429
429
/**
430
430
* Returns a power of two >= `target`.
431
431
*/
432
- private [collection] def powerOfTwo (target : Int ): Int = {
433
- /* See http://bits.stephan-brumme.com/roundUpToNextPowerOfTwo.html */
434
- var c = target - 1
435
- c |= c >>> 1
436
- c |= c >>> 2
437
- c |= c >>> 4
438
- c |= c >>> 8
439
- c |= c >>> 16
440
- c + 1
441
- }
432
+ private [collection] def nextPositivePowerOfTwo (target : Int ): Int = 1 << - numberOfLeadingZeros(target - 1 )
442
433
443
434
class Contents [A , Entry >: Null <: HashEntry [A , Entry ]](
444
435
val loadFactor : Int ,
Original file line number Diff line number Diff line change @@ -31,8 +31,6 @@ object OpenHashMap {
31
31
final private class OpenEntry [Key , Value ](var key : Key ,
32
32
var hash : Int ,
33
33
var value : Option [Value ])
34
-
35
- private [mutable] def nextPositivePowerOfTwo (i : Int ) = 1 << (32 - Integer .numberOfLeadingZeros(i - 1 ))
36
34
}
37
35
38
36
/** A mutable hash map based on an open hashing scheme. The precise scheme is
@@ -67,7 +65,7 @@ extends AbstractMap[Key, Value]
67
65
68
66
override def empty : OpenHashMap [Key , Value ] = OpenHashMap .empty[Key , Value ]
69
67
70
- private [this ] val actualInitialSize = OpenHashMap .nextPositivePowerOfTwo(initialSize)
68
+ private [this ] val actualInitialSize = HashTable .nextPositivePowerOfTwo(initialSize)
71
69
72
70
private var mask = actualInitialSize - 1
73
71
You can’t perform that action at this time.
0 commit comments