File tree Expand file tree Collapse file tree 2 files changed +25
-15
lines changed
compiler/src/dotty/tools/dotc/util Expand file tree Collapse file tree 2 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,7 @@ package dotty.tools.dotc.util
22
33/** A common class for lightweight mutable sets.
44 */
5- abstract class MutableSet [T ] {
6-
7- /** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
8- def lookup (x : T ): T | Null
5+ abstract class MutableSet [T ] extends ReadOnlySet [T ]:
96
107 /** Add element `x` to the set */
118 def += (x : T ): Unit
@@ -17,14 +14,3 @@ abstract class MutableSet[T] {
1714
1815 def clear (): Unit
1916
20- def size : Int
21-
22- def iterator : Iterator [T ]
23-
24- def contains (x : T ): Boolean = lookup(x) != null
25-
26- def foreach [U ](f : T => U ): Unit = iterator foreach f
27-
28- def toList : List [T ] = iterator.toList
29-
30- }
Original file line number Diff line number Diff line change 1+ package dotty .tools .dotc .util
2+
3+ /** A class for the readonly part of mutable sets.
4+ */
5+ abstract class ReadOnlySet [T ]:
6+
7+ /** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
8+ def lookup (x : T ): T | Null
9+
10+ def size : Int
11+
12+ def iterator : Iterator [T ]
13+
14+ def contains (x : T ): Boolean = lookup(x) != null
15+
16+ def foreach [U ](f : T => U ): Unit = iterator.foreach(f)
17+
18+ def toList : List [T ] = iterator.toList
19+
20+ def isEmpty = size == 0
21+
22+ object ReadOnlySet :
23+ def empty [T ]: ReadOnlySet [T ] = HashSet [T ](4 )
24+
You can’t perform that action at this time.
0 commit comments