|
Scala example source code file (t2849.scala)
The Scala t2849.scala source code
import scala.collection.immutable.SortedSet
import scala.collection.immutable.TreeSet
object Test {
def main(args: Array[String]) {
ticketExample
similarExample
}
//def freeMBytes = Runtime.getRuntime.freeMemory / 1048576
def totalMBytes = Runtime.getRuntime.totalMemory / 1048576
val N = if (totalMBytes > 1000) 10000 else 4000
val M = N / 10
def ticketExample {
var big = 100000
var aSortedSet: SortedSet[Int] = TreeSet(big)
for (i <- 1 until N) {
aSortedSet = (aSortedSet - big) ++ (TreeSet(i, big - 1))
big -= 1
if (i % M == 0) {
//println("big: "+big+", free memory: "+freeMBytes)
aSortedSet.until(i)
}
}
}
def similarExample {
var big = 100
var aSortedSet: SortedSet[Int] = TreeSet(big)
for (i <- 1 until N) {
aSortedSet = (aSortedSet - big) ++ (TreeSet(i, big - 1)) + big
big -= 1
if (i % M == 0) {
aSortedSet.until(i)
}
}
}
}
Other Scala examples (source code examples)Here is a short list of links related to this Scala t2849.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.