@@ -9,6 +9,10 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
9
9
10
10
protected def isEqual (x : T , y : T ): Boolean = x.equals(y)
11
11
12
+ // Counters for Stats
13
+ var accesses = 0
14
+ var misses = 0
15
+
12
16
clear()
13
17
14
18
/** The number of elements in the set */
@@ -37,10 +41,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
37
41
* If not, enter `x` in set and return `x`.
38
42
*/
39
43
def findEntryOrUpdate (x : T ): T = {
44
+ if (Stats .enabled) accesses += 1
40
45
var h = index(hash(x))
41
46
var entry = entryAt(h)
42
47
while (entry ne null ) {
43
48
if (isEqual(x, entry)) return entry
49
+ if (Stats .enabled) misses += 1
44
50
h = index(h + 1 )
45
51
entry = entryAt(h)
46
52
}
@@ -57,9 +63,11 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
57
63
58
64
/** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
59
65
def findEntry (x : T ): T = {
66
+ if (Stats .enabled) accesses += 1
60
67
var h = index(hash(x))
61
68
var entry = entryAt(h)
62
69
while ((entry ne null ) && ! isEqual(x, entry)) {
70
+ if (Stats .enabled) misses += 1
63
71
h = index(h + 1 )
64
72
entry = entryAt(h)
65
73
}
@@ -70,10 +78,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
70
78
71
79
/** Add entry `x` to set */
72
80
def addEntry (x : T ): Unit = {
81
+ if (Stats .enabled) accesses += 1
73
82
var h = index(hash(x))
74
83
var entry = entryAt(h)
75
84
while (entry ne null ) {
76
85
if (isEqual(x, entry)) return
86
+ if (Stats .enabled) misses += 1
77
87
h = index(h + 1 )
78
88
entry = entryAt(h)
79
89
}
@@ -109,10 +119,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
109
119
* follow a `findEntryByhash` or `nextEntryByHash` operation.
110
120
*/
111
121
protected def nextEntryByHash (hashCode : Int ): T = {
122
+ if (Stats .enabled) accesses += 1
112
123
var entry = table(rover)
113
124
while (entry ne null ) {
114
125
rover = index(rover + 1 )
115
126
if (hash(entry.asInstanceOf [T ]) == hashCode) return entry.asInstanceOf [T ]
127
+ if (Stats .enabled) misses += 1
116
128
entry = table(rover)
117
129
}
118
130
null
0 commit comments