diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-05-30 14:08:41 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-01 17:24:47 +0200 |
commit | d38ad5e9877011e635b6c2cb6c4f3fcb31dfb7d2 (patch) | |
tree | da7ca5ffe16846f75b27b48dc6f932b08b471058 /test/files/run/triemap-hash.scala | |
parent | 8d38079ab457e77b3ba57076f3766a158c1eb030 (diff) | |
download | scala-d38ad5e9877011e635b6c2cb6c4f3fcb31dfb7d2.tar.gz scala-d38ad5e9877011e635b6c2cb6c4f3fcb31dfb7d2.tar.bz2 scala-d38ad5e9877011e635b6c2cb6c4f3fcb31dfb7d2.zip |
Add Hashing and Equality typeclasses.
Modify TrieMap to use hashing and equality.
Modify serialization in TrieMap appropriately.
Diffstat (limited to 'test/files/run/triemap-hash.scala')
-rw-r--r-- | test/files/run/triemap-hash.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/files/run/triemap-hash.scala b/test/files/run/triemap-hash.scala new file mode 100644 index 0000000000..23cdd26bed --- /dev/null +++ b/test/files/run/triemap-hash.scala @@ -0,0 +1,46 @@ + + + +import math.Hashing + + + +object Test { + + def main(args: Array[String]) { + hashing() + equality() + } + + def hashing() { + import collection._ + + val tm = new concurrent.TrieMap[String, String](Hashing(x => x.length + x(0).toInt), Equality.defaultEquality) + tm.put("a", "b") + tm.put("c", "d") + + assert(tm("a") == "b") + assert(tm("c") == "d") + + for (i <- 0 until 1000) tm(i.toString) = i.toString + for (i <- 0 until 1000) assert(tm(i.toString) == i.toString) + } + + def equality() { + import collection._ + + val tm = new concurrent.TrieMap[String, String](Hashing(x => x(0).toInt), Equality(_(0) == _(0))) + tm.put("a", "b") + tm.put("a1", "d") + tm.put("b", "c") + + assert(tm("a") == "d", tm) + assert(tm("b") == "c", tm) + + for (i <- 0 until 1000) tm(i.toString) = i.toString + assert(tm.size == 12, tm) + assert(tm("0") == "0", tm) + for (i <- 1 to 9) assert(tm(i.toString) == i.toString + "99", tm) + } + +} |