File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
compiler/src/dotty/tools/dotc/util Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc .util
2
+
3
+ import scala .collection .mutable .ArrayBuffer
4
+
5
+ class EqLinkedHashSet [T ](
6
+ initialCapacity : Int = 8 , capacityMultiple : Int = 2
7
+ ) extends MutableSet [T ] {
8
+
9
+ private val map : MutableMap [T , Unit ] = new EqHashMap (initialCapacity, capacityMultiple)
10
+ private val linkingArray : ArrayBuffer [T ] = new ArrayBuffer (initialCapacity)
11
+
12
+ override def += (x : T ): Unit =
13
+ map.update(x, ())
14
+ if map.size != linkingArray.size then linkingArray += x
15
+
16
+ override def put (x : T ): T =
17
+ this += x
18
+ x
19
+
20
+ override def -= (x : T ): Unit =
21
+ map -= x
22
+ if map.size != linkingArray.size then linkingArray -= x
23
+
24
+ override def clear (): Unit =
25
+ map.clear()
26
+ linkingArray.clear()
27
+
28
+ override def lookup (x : T ): T | Null = if map.contains(x) then x else null
29
+
30
+ override def size : Int = map.size
31
+
32
+ override def iterator : Iterator [T ] = linkingArray.iterator
33
+
34
+ }
35
+
36
+ object EqLinkedHashSet {
37
+ def apply [T ](x : T ): EqLinkedHashSet [T ] =
38
+ val set = new EqLinkedHashSet [T ]
39
+ set += x
40
+ set
41
+
42
+ def apply [T ](x : T , y : T ): EqLinkedHashSet [T ] =
43
+ val set = EqLinkedHashSet (x)
44
+ set += y
45
+ set
46
+ }
You can’t perform that action at this time.
0 commit comments