@@ -269,19 +269,14 @@ final class LongMap[V] private[collection] (defaultEntry: Long => V, initialBuff
269
269
}
270
270
271
271
/** Repacks the contents of this `LongMap` for maximum efficiency of lookup.
272
- *
273
- * For maps that undergo a complex creation process with both addition and
274
- * removal of keys, and then are used heavily with no further removal of
275
- * elements, calling `repack` after the end of the creation can result in
276
- * improved performance. Repacking takes time proportional to the number
277
- * of entries in the map.
278
- */
279
- def repack (): Unit = {
280
- var m = mask
281
- if (_size + _vacant >= 0.5 * mask && ! (_vacant > 0.2 * mask)) m = ((m << 1 ) + 1 ) & IndexMask
282
- while (m > 8 && 8 * _size < m) m = m >>> 1
283
- repack(m)
284
- }
272
+ *
273
+ * For maps that undergo a complex creation process with both addition and
274
+ * removal of keys, and then are used heavily with no further removal of
275
+ * elements, calling `repack` after the end of the creation can result in
276
+ * improved performance. Repacking takes time proportional to the number
277
+ * of entries in the map.
278
+ */
279
+ def repack (): Unit = repack(repackMask(mask, _size = _size, _vacant = _vacant))
285
280
286
281
override def put (key : Long , value : V ): Option [V ] = {
287
282
if (key == - key) {
@@ -587,10 +582,10 @@ final class LongMap[V] private[collection] (defaultEntry: Long => V, initialBuff
587
582
}
588
583
589
584
object LongMap {
590
- private final val IndexMask = 0x3FFFFFFF
591
- private final val MissingBit = 0x80000000
592
- private final val VacantBit = 0x40000000
593
- private final val MissVacant = 0xC0000000
585
+ private final val IndexMask = 0x3FFF_FFFF
586
+ private final val MissingBit = 0x8000_0000
587
+ private final val VacantBit = 0x4000_0000
588
+ private final val MissVacant = 0xC000_0000
594
589
595
590
private val exceptionDefault : Long => Nothing = (k : Long ) => throw new NoSuchElementException (k.toString)
596
591
@@ -682,4 +677,11 @@ object LongMap {
682
677
683
678
implicit def iterableFactory [V ]: Factory [(Long , V ), LongMap [V ]] = toFactory(this )
684
679
implicit def buildFromLongMap [V ]: BuildFrom [LongMap [_], (Long , V ), LongMap [V ]] = toBuildFrom(this )
680
+
681
+ private def repackMask (mask : Int , _size : Int , _vacant : Int ): Int = {
682
+ var m = mask
683
+ if (_size + _vacant >= 0.5 * mask && ! (_vacant > 0.2 * mask)) m = ((m << 1 ) + 1 ) & IndexMask
684
+ while (m > 8 && _size < (m >>> 3 )) m = m >>> 1
685
+ m /* .ensuring(_size <= _ + 1)*/
686
+ }
685
687
}
0 commit comments