|
Scala example source code file (hashCodeDistribution.scala)
The Scala hashCodeDistribution.scala source code
// See ticket #2537.
object Test {
case class C(x: Int, y: Int) { }
val COUNT = 300
val totalCodes = COUNT * COUNT
def main (args: Array[String]) = {
val hashCodes =
for (x <- 0 until COUNT; y <- 0 until COUNT) yield C(x,y).hashCode
val uniques = hashCodes.distinct
val collisionRate = (totalCodes - uniques.size) * 1000 / totalCodes
assert(collisionRate < 5, "Collision rate too high: %d / 1000".format(collisionRate))
// println("collisionRate = %d / 1000".format(collisionRate))
}
}
Other Scala examples (source code examples)Here is a short list of links related to this Scala hashCodeDistribution.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.