Skip to content

Commit 99898df

Browse files
committed
Fix HashMap remove criterion
Make criterion when to fill a hole in a HashMap remove more robust. The old criterion relied on fill factor always being less than 0.5. The new criterion works for arbitrary fill factors.
1 parent 5a37540 commit 99898df

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

compiler/src/dotty/tools/dotc/util/HashSet.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
109109
e = entryAt(idx)
110110
e != null
111111
do
112+
val eidx = index(hash(e))
112113
if isDense
113-
|| index(hole - index(hash(e))) < limit
114-
// hash(k) is then logically at or before hole; can be moved forward to fill hole
114+
|| index(eidx - (hole + 2)) > index(idx - (hole + 2))
115+
// entry `e` at `idx` can move unless `index(hash(e))` is in
116+
// the (ring-)interval [hole + 2 .. idx]
115117
then
116118
setEntry(hole, e)
117119
hole = idx

0 commit comments

Comments
 (0)