aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/util/lrutest.sc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-03-03 14:53:04 +0100
committerMartin Odersky <odersky@gmail.com>2013-03-03 15:13:18 +0100
commit30bfa5b1be62652fc07292d36ed1261edbcdb362 (patch)
treeb5329b2721a65170b2ff6623400d0bb7cbf51bcb /src/dotty/tools/dotc/util/lrutest.sc
parent24f5a1ef4b8a49b6a2a8c684c1c98bc6a5293813 (diff)
downloaddotty-30bfa5b1be62652fc07292d36ed1261edbcdb362.tar.gz
dotty-30bfa5b1be62652fc07292d36ed1261edbcdb362.tar.bz2
dotty-30bfa5b1be62652fc07292d36ed1261edbcdb362.zip
New LRU Cache implementation
Diffstat (limited to 'src/dotty/tools/dotc/util/lrutest.sc')
-rw-r--r--src/dotty/tools/dotc/util/lrutest.sc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/util/lrutest.sc b/src/dotty/tools/dotc/util/lrutest.sc
new file mode 100644
index 000000000..6e6328b24
--- /dev/null
+++ b/src/dotty/tools/dotc/util/lrutest.sc
@@ -0,0 +1,40 @@
+package dotty.tools.dotc.util
+
+object lrutest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+ val bits = new SixteenNibbles(0L) //> bits : dotty.tools.dotc.util.SixteenNibbles = SixteenNibbles(0, 0, 0, 0, 0,
+ //| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ bits.updated(1, 3) //> res0: dotty.tools.dotc.util.SixteenNibbles = SixteenNibbles(0, 3, 0, 0, 0, 0
+ //| , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ LRUCache.initialRing //> res1: dotty.tools.dotc.util.SixteenNibbles = SixteenNibbles(1, 2, 3, 4, 5, 6
+ //| , 7, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ val cache = new LRUCache[String, String] //> cache : dotty.tools.dotc.util.LRUCache[String,String] = LRUCache()
+ cache lookup "hi" //> res2: String = null
+ cache enter ("hi", "x")
+ cache.indices.take(10).toList //> res3: List[Int] = List(7, 0, 1, 2, 3, 4, 5, 6, 7, 0)
+ cache.last //> res4: Int = 6
+ cache lookup "hi" //> res5: String = x
+ cache.indices.take(10).toList //> res6: List[Int] = List(7, 0, 1, 2, 3, 4, 5, 6, 7, 0)
+
+ for (i <- 1 to 10) {
+ if (cache.lookup(i.toString) == null)
+ cache.enter(i.toString, i.toString)
+ }
+
+ cache.indices.take(10).toList //> res7: List[Int] = List(5, 6, 7, 0, 1, 2, 3, 4, 5, 6)
+ cache //> res8: dotty.tools.dotc.util.LRUCache[String,String] = LRUCache(10 -> 10, 9 -
+ //| > 9, 8 -> 8, 7 -> 7, 6 -> 6, 5 -> 5, 4 -> 4, 3 -> 3)
+ cache //> res9: dotty.tools.dotc.util.LRUCache[String,String] = LRUCache(10 -> 10, 9 -
+ //| > 9, 8 -> 8, 7 -> 7, 6 -> 6, 5 -> 5, 4 -> 4, 3 -> 3)
+ cache.lookup("7") //> res10: String = 7
+ cache.indices.take(10).toList //> res11: List[Int] = List(0, 5, 6, 7, 1, 2, 3, 4, 0, 5)
+ cache.keysIterator.toList //> res12: List[String] = List(7, 10, 9, 8, 6, 5, 4, 3)
+ cache.lookup("10") //> res13: String = 10
+ cache.lookup("5") //> res14: String = 5
+ cache //> res15: dotty.tools.dotc.util.LRUCache[String,String] = LRUCache(5 -> 5, 10 -
+ //| > 10, 7 -> 7, 9 -> 9, 8 -> 8, 6 -> 6, 4 -> 4, 3 -> 3)
+ cache.lookup("11") //> res16: String = null
+ cache.enter("11", "!!")
+ cache //> res17: dotty.tools.dotc.util.LRUCache[String,String] = LRUCache(11 -> !!, 5
+ //| -> 5, 10 -> 10, 7 -> 7, 9 -> 9, 8 -> 8, 6 -> 6, 4 -> 4)
+} \ No newline at end of file