Fixed an overflow which occurs in hashtable size computations. Fixes #4678.
No review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25112 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
d3972c254c
commit
295d07a78f
|
@ -323,7 +323,7 @@ private[collection] object FlatHashTable {
|
||||||
*/
|
*/
|
||||||
private[collection] def initialSize: Int = 16
|
private[collection] def initialSize: Int = 16
|
||||||
|
|
||||||
private[collection] def sizeForThreshold(size: Int, _loadFactor: Int) = size * loadFactorDenum / _loadFactor
|
private[collection] def sizeForThreshold(size: Int, _loadFactor: Int) = (size.toLong * loadFactorDenum / _loadFactor).toInt
|
||||||
|
|
||||||
private[collection] def newThreshold(_loadFactor: Int, size: Int) = {
|
private[collection] def newThreshold(_loadFactor: Int, size: Int) = {
|
||||||
val lf = _loadFactor
|
val lf = _loadFactor
|
||||||
|
|
|
@ -178,6 +178,8 @@ with collection.mutable.FlatHashTable.HashUtils[T] {
|
||||||
threshold = FlatHashTable.newThreshold(_loadFactor, table.length)
|
threshold = FlatHashTable.newThreshold(_loadFactor, table.length)
|
||||||
sizeMapInit(table.length)
|
sizeMapInit(table.length)
|
||||||
|
|
||||||
|
override def toString = "AFHT(%s)".format(table.length)
|
||||||
|
|
||||||
def tableLength = table.length
|
def tableLength = table.length
|
||||||
|
|
||||||
def setSize(sz: Int) = tableSize = sz
|
def setSize(sz: Int) = tableSize = sz
|
||||||
|
@ -194,7 +196,7 @@ with collection.mutable.FlatHashTable.HashUtils[T] {
|
||||||
* the table will try to add the element in such a position if possible. Collisions are resolved
|
* the table will try to add the element in such a position if possible. Collisions are resolved
|
||||||
* using linear hashing, so the element may actually have to be added to a position
|
* using linear hashing, so the element may actually have to be added to a position
|
||||||
* that follows the specified one. In the case that the first unoccupied position
|
* that follows the specified one. In the case that the first unoccupied position
|
||||||
* comes after `comesBefore`, the element is not added and the method simply returns `-1`,
|
* comes after `comesBefore`, the element is not added and the method simply returns -1,
|
||||||
* indicating that it couldn't add the element in a position that comes before the
|
* indicating that it couldn't add the element in a position that comes before the
|
||||||
* specified one.
|
* specified one.
|
||||||
* If the element is already present in the hash table, it is not added, and this method
|
* If the element is already present in the hash table, it is not added, and this method
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import scala.collection.parallel.{ ParMap => PMap }
|
||||||
|
import scala.collection.parallel.mutable.{ ParHashSet => PMHashSet, ParHashMap => PMHashMap, ParArray }
|
||||||
|
import scala.util.Random
|
||||||
|
import scala.collection.parallel.CompositeThrowable
|
||||||
|
|
||||||
|
object Test {
|
||||||
|
|
||||||
|
def main(args: Array[String]) {
|
||||||
|
val N = 1500
|
||||||
|
val M = 1500
|
||||||
|
var unmatchedLeft = new PMHashSet[Int]
|
||||||
|
var unmatchedRight = new PMHashSet[Int]
|
||||||
|
Range(0, N).foreach{ x => unmatchedLeft += x}
|
||||||
|
Range(0, M).foreach{ x => unmatchedRight += x}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val matches = unmatchedLeft.flatMap{ lind: Int =>
|
||||||
|
val dists = unmatchedRight.seq.map{ rind: Int =>
|
||||||
|
val dist = Random.nextInt
|
||||||
|
(rind, dist)
|
||||||
|
}
|
||||||
|
dists
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
case c: CompositeThrowable => for (t <- c.throwables) println("\n%s\n%s".format(t, t.getStackTrace.mkString("\n")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue