diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-04 06:36:03 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-04 06:36:03 +0000 |
commit | f5ede0923cd8dd2d45853a06e71e05052e462213 (patch) | |
tree | 731d9f9314e9a1762dd9f513cce15dff8b231829 /test/files | |
parent | b02b388ffaa5ea6d62669bb91d8af6de521aa71f (diff) | |
download | scala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.gz scala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.bz2 scala-f5ede0923cd8dd2d45853a06e71e05052e462213.zip |
Scala implementation of fancier hashCode algori...
Scala implementation of fancier hashCode algorithm. At the moment it
isn't used unless you supply -Yjenkins-hashCodes to scalac. Without the
flag, the supplied test case generates 12559 unique hashCodes among
90000 case class instances; with the flag it generates 89999.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/hashCodeDistribution.flags | 1 | ||||
-rw-r--r-- | test/files/run/hashCodeDistribution.scala | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/test/files/run/hashCodeDistribution.flags b/test/files/run/hashCodeDistribution.flags new file mode 100644 index 0000000000..7806652d4d --- /dev/null +++ b/test/files/run/hashCodeDistribution.flags @@ -0,0 +1 @@ +-Yjenkins-hashCodes
\ No newline at end of file diff --git a/test/files/run/hashCodeDistribution.scala b/test/files/run/hashCodeDistribution.scala new file mode 100644 index 0000000000..dbb6e833bd --- /dev/null +++ b/test/files/run/hashCodeDistribution.scala @@ -0,0 +1,17 @@ +// 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.removeDuplicates + val collisionRate = (totalCodes - uniques.size) * 1000 / totalCodes + + assert(collisionRate < 5, "Collision rate too high: %d / 1000".format(collisionRate)) + // println("collisionRate = %d / 1000".format(collisionRate)) + } +}
\ No newline at end of file |