File tree 2 files changed +25
-15
lines changed
compiler/src/dotty/tools/dotc/util 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
2
2
3
3
/** A common class for lightweight mutable sets.
4
4
*/
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 ]:
9
6
10
7
/** Add element `x` to the set */
11
8
def += (x : T ): Unit
@@ -17,14 +14,3 @@ abstract class MutableSet[T] {
17
14
18
15
def clear (): Unit
19
16
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