@@ -14,6 +14,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
14
14
15
15
private def allocate (size : Int ) = {
16
16
table = new Array [AnyRef ](size)
17
+ checkTread
17
18
limit = (size * loadFactor).toInt
18
19
}
19
20
@@ -47,6 +48,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
47
48
private def addEntryAt (idx : Int , x : T ) = {
48
49
table(idx) = x
49
50
used += 1
51
+ checkTread
50
52
if (used > limit) growTable()
51
53
x
52
54
}
@@ -63,6 +65,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
63
65
}
64
66
65
67
private var rover : Int = - 1
68
+ private var thread : Thread = null
66
69
67
70
/** Add entry `x` to set */
68
71
def addEntry (x : T ): Unit = {
@@ -75,6 +78,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
75
78
}
76
79
table(h) = x
77
80
used += 1
81
+ checkTread
78
82
if (used > (table.length >> 2 )) growTable()
79
83
}
80
84
@@ -95,8 +99,15 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
95
99
else null
96
100
}
97
101
102
+ private def checkTread : Unit = {
103
+ if (thread == null )
104
+ thread = Thread .currentThread()
105
+ else assert(thread == Thread .currentThread())
106
+ }
107
+
98
108
/** Privileged access: Find first entry with given hashcode */
99
109
protected def findEntryByHash (hashCode : Int ): T = {
110
+ checkTread
100
111
rover = index(hashCode)
101
112
nextEntryByHash(hashCode)
102
113
}
@@ -107,6 +118,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
107
118
protected def nextEntryByHash (hashCode : Int ): T = {
108
119
var entry = table(rover)
109
120
while (entry ne null ) {
121
+ checkTread
110
122
rover = index(rover + 1 )
111
123
if (hash(entry.asInstanceOf [T ]) == hashCode) return entry.asInstanceOf [T ]
112
124
entry = table(rover)
@@ -124,6 +136,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.2
124
136
private def addOldEntry (x : T ): Unit = {
125
137
var h = index(hash(x))
126
138
var entry = table(h)
139
+ checkTread
127
140
while (entry ne null ) {
128
141
h = index(h + 1 )
129
142
entry = table(h)
0 commit comments