summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-01-09 11:24:54 +0000
committerGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-01-09 11:24:54 +0000
commita315748a73106cc5720546947ce6b11ea021f322 (patch)
tree1323808aa5d7ce1301c76ebe19f8dc907f6e9846
parent5ca37b791e7f99442ed91a1503f08d422303d412 (diff)
downloadscala-a315748a73106cc5720546947ce6b11ea021f322.tar.gz
scala-a315748a73106cc5720546947ce6b11ea021f322.tar.bz2
scala-a315748a73106cc5720546947ce6b11ea021f322.zip
Applied patch from Ticket #334.
Ensures that the modulus of the hashcode is non-negative.
-rw-r--r--src/compiler/scala/tools/nsc/util/HashSet.scala10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/util/HashSet.scala b/src/compiler/scala/tools/nsc/util/HashSet.scala
index 818f19f1f1..4677676976 100644
--- a/src/compiler/scala/tools/nsc/util/HashSet.scala
+++ b/src/compiler/scala/tools/nsc/util/HashSet.scala
@@ -16,22 +16,24 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int) extends Set[T] {
def size: Int = used
+ private def index(x: Int): Int = Math.abs(x % capacity)
+
def findEntry(x: T): T = {
- var h = x.hashCode() % capacity
+ var h = index(x.hashCode())
var entry = table(h)
while ((entry ne null) && entry != x) {
- h = (h + 1) % capacity
+ h = index(h + 1)
entry = table(h)
}
entry.asInstanceOf[T]
}
def addEntry(x: T) {
- var h = x.hashCode() % capacity
+ var h = index(x.hashCode())
var entry = table(h)
while (entry ne null) {
if (entry == x) return
- h = (h + 1) % capacity
+ h = index((h + 1))
entry = table(h)
}
table(h) = x