@@ -23,7 +23,7 @@ object GenericHashMap:
2323 * However, a table of size up to DenseLimit will be re-sized only
2424 * once the number of elements reaches the table's size.
2525 */
26- abstract class GenericHashMap [Key <: AnyRef , Value ]
26+ abstract class GenericHashMap [Key , Value ]
2727 (initialCapacity : Int , capacityMultiple : Int ) extends MutableMap [Key , Value ]:
2828 import GenericHashMap .DenseLimit
2929
@@ -58,18 +58,20 @@ abstract class GenericHashMap[Key <: AnyRef, Value]
5858 protected def isEqual (x : Key , y : Key ): Boolean
5959
6060 /** Turn successor index or hash code `x` into a table index */
61- inline protected def index (x : Int ): Int = x & (table.length - 2 )
61+ private def index (x : Int ): Int = x & (table.length - 2 )
6262
63- inline protected def firstIndex (key : Key ) = if isDense then 0 else index(hash(key))
64- inline protected def nextIndex (idx : Int ) =
63+ private def firstIndex (key : Key ) = if isDense then 0 else index(hash(key))
64+ private def nextIndex (idx : Int ) =
6565 Stats .record(statsItem(" miss" ))
6666 index(idx + 2 )
6767
68- inline protected def keyAt (idx : Int ): Key = table(idx).asInstanceOf [Key ]
69- inline protected def valueAt (idx : Int ): Value = table(idx + 1 ).asInstanceOf [Value ]
68+ private def keyAt (idx : Int ): Key = table(idx).asInstanceOf [Key ]
69+ private def valueAt (idx : Int ): Value = table(idx + 1 ).asInstanceOf [Value ]
7070
71- inline protected def setTable (idx : Int , value : Value ) =
72- table(idx) = value.asInstanceOf [AnyRef ]
71+ private def setKey (idx : Int , key : Key ) =
72+ table(idx) = key.asInstanceOf [AnyRef ]
73+ private def setValue (idx : Int , value : Value ) =
74+ table(idx + 1 ) = value.asInstanceOf [AnyRef ]
7375
7476 def lookup (key : Key ): Value | Null =
7577 Stats .record(statsItem(" lookup" ))
@@ -87,12 +89,12 @@ abstract class GenericHashMap[Key <: AnyRef, Value]
8789 var k = keyAt(idx)
8890 while k != null do
8991 if isEqual(k, key) then
90- setTable (idx + 1 , value)
92+ setValue (idx, value)
9193 return
9294 idx = nextIndex(idx)
9395 k = keyAt(idx)
94- table (idx) = key
95- setTable (idx + 1 , value)
96+ setKey (idx, key)
97+ setValue (idx, value)
9698 used += 1
9799 if used > limit then growTable()
98100
@@ -112,8 +114,8 @@ abstract class GenericHashMap[Key <: AnyRef, Value]
112114 || index(hole - index(hash(k))) < limit * 2
113115 // hash(k) is then logically at or before hole; can be moved forward to fill hole
114116 then
115- table (hole) = k
116- setTable (hole + 1 , valueAt(idx))
117+ setKey (hole, k)
118+ setValue (hole, valueAt(idx))
117119 hole = idx
118120 table(hole) = null
119121 used -= 1
@@ -126,15 +128,15 @@ abstract class GenericHashMap[Key <: AnyRef, Value]
126128 if v == null then v = value
127129 v.uncheckedNN
128130
129- private def addOld (key : Key , value : AnyRef ): Unit =
131+ private def addOld (key : Key , value : Value ): Unit =
130132 Stats .record(statsItem(" re-enter" ))
131133 var idx = firstIndex(key)
132134 var k = keyAt(idx)
133135 while k != null do
134136 idx = nextIndex(idx)
135137 k = keyAt(idx)
136- table (idx) = key
137- table (idx + 1 ) = value
138+ setKey (idx, key)
139+ setValue (idx, value)
138140
139141 def copyFrom (oldTable : Array [AnyRef ]): Unit =
140142 if isDense then
@@ -143,7 +145,7 @@ abstract class GenericHashMap[Key <: AnyRef, Value]
143145 var idx = 0
144146 while idx < oldTable.length do
145147 val key = oldTable(idx).asInstanceOf [Key ]
146- if key != null then addOld(key, oldTable(idx + 1 ))
148+ if key != null then addOld(key, oldTable(idx + 1 ). asInstanceOf [ Value ] )
147149 idx += 2
148150
149151 protected def growTable (): Unit =
0 commit comments