summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/FlatHashTable.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-03-05 15:22:00 +0000
committerMartin Odersky <odersky@gmail.com>2007-03-05 15:22:00 +0000
commit3f05775fadd5c6c32eda33bbf50b5d044ab30ef8 (patch)
tree3c0d97e75fa9a894f43b7a4d0cc4f65b6029d9b6 /src/library/scala/collection/mutable/FlatHashTable.scala
parent2c11ab6c75c4389a35d029aeb69d5d437e83a85a (diff)
downloadscala-3f05775fadd5c6c32eda33bbf50b5d044ab30ef8.tar.gz
scala-3f05775fadd5c6c32eda33bbf50b5d044ab30ef8.tar.bz2
scala-3f05775fadd5c6c32eda33bbf50b5d044ab30ef8.zip
fixed bug978
Diffstat (limited to 'src/library/scala/collection/mutable/FlatHashTable.scala')
-rw-r--r--src/library/scala/collection/mutable/FlatHashTable.scala15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala
index 0c9ec9c4d6..aeab7cd2ea 100644
--- a/src/library/scala/collection/mutable/FlatHashTable.scala
+++ b/src/library/scala/collection/mutable/FlatHashTable.scala
@@ -18,6 +18,8 @@ trait FlatHashTable[A] {
*/
protected def initialSize: Int = 16
+ private final val tableDebug = false
+
/** The actual hash table.
*/
protected var table: Array[AnyRef] =
@@ -69,8 +71,9 @@ trait FlatHashTable[A] {
}
def removeEntry(elem: A) {
+ checkConsistent()
def precedes(i: int, j: int) = {
- val d = table.length >> 2
+ val d = table.length >> 1
if (i <= j) j - i < d
else i - j > d
}
@@ -82,7 +85,7 @@ trait FlatHashTable[A] {
var h1 = (h0 + 1) % table.length
while (null != table(h1)) {
val h2 = index(elemHashCode(table(h1).asInstanceOf[A]))
- //Console.println("shift at "+h1+":"+table(h1)+" with h2 = "+h2+"?")
+ //Console.println("shift at "+h1+":"+table(h1)+" with h2 = "+h2+"? "+(h2 != h1)+precedes(h2, h0)+table.length)
if (h2 != h1 && precedes(h2, h0)) {
//Console.println("shift "+h1+" to "+h0+"!")
table(h0) = table(h1)
@@ -92,6 +95,7 @@ trait FlatHashTable[A] {
}
table(h0) = null
tableSize = tableSize - 1
+ if (tableDebug) checkConsistent()
return
}
h = (h + 1) % table.length
@@ -121,6 +125,13 @@ trait FlatHashTable[A] {
if (null != entry) addEntry(entry.asInstanceOf[A])
i = i + 1
}
+ if (tableDebug) checkConsistent()
+ }
+
+ private def checkConsistent() {
+ for (val i <- 0 until table.length)
+ if (table(i) != null && !containsEntry(table(i).asInstanceOf[A]))
+ assert(false, i+" "+table(i)+" "+table.toString)
}
protected def elemHashCode(elem: A) = elem.hashCode()