@@ -9,6 +9,10 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
99
1010 protected def isEqual (x : T , y : T ): Boolean = x.equals(y)
1111
12+ // Counters for Stats
13+ var accesses = 0
14+ var misses = 0
15+
1216 clear()
1317
1418 /** The number of elements in the set */
@@ -37,10 +41,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
3741 * If not, enter `x` in set and return `x`.
3842 */
3943 def findEntryOrUpdate (x : T ): T = {
44+ if (Stats .enabled) accesses += 1
4045 var h = index(hash(x))
4146 var entry = entryAt(h)
4247 while (entry ne null ) {
4348 if (isEqual(x, entry)) return entry
49+ if (Stats .enabled) misses += 1
4450 h = index(h + 1 )
4551 entry = entryAt(h)
4652 }
@@ -57,9 +63,11 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
5763
5864 /** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
5965 def findEntry (x : T ): T = {
66+ if (Stats .enabled) accesses += 1
6067 var h = index(hash(x))
6168 var entry = entryAt(h)
6269 while ((entry ne null ) && ! isEqual(x, entry)) {
70+ if (Stats .enabled) misses += 1
6371 h = index(h + 1 )
6472 entry = entryAt(h)
6573 }
@@ -70,10 +78,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
7078
7179 /** Add entry `x` to set */
7280 def addEntry (x : T ): Unit = {
81+ if (Stats .enabled) accesses += 1
7382 var h = index(hash(x))
7483 var entry = entryAt(h)
7584 while (entry ne null ) {
7685 if (isEqual(x, entry)) return
86+ if (Stats .enabled) misses += 1
7787 h = index(h + 1 )
7888 entry = entryAt(h)
7989 }
@@ -109,10 +119,12 @@ class HashSet[T >: Null <: AnyRef](powerOfTwoInitialCapacity: Int, loadFactor: F
109119 * follow a `findEntryByhash` or `nextEntryByHash` operation.
110120 */
111121 protected def nextEntryByHash (hashCode : Int ): T = {
122+ if (Stats .enabled) accesses += 1
112123 var entry = table(rover)
113124 while (entry ne null ) {
114125 rover = index(rover + 1 )
115126 if (hash(entry.asInstanceOf [T ]) == hashCode) return entry.asInstanceOf [T ]
127+ if (Stats .enabled) misses += 1
116128 entry = table(rover)
117129 }
118130 null
0 commit comments