Skip to content

Instantly share code, notes, and snippets.

@t1anchen
Created November 21, 2013 16:29
Show Gist options
  • Save t1anchen/7584966 to your computer and use it in GitHub Desktop.
Save t1anchen/7584966 to your computer and use it in GitHub Desktop.
jar package manually
scalac GetLines.scala && COPY %SCALA_HOME%\lib\scala-library.jar . && jar cfm getlines.jar manifest.txt *.class *.jar && java -jar getlines.jar dict.txt
import scala.collection.mutable.BitSet
import scala.collection.mutable.Map
// Don't learn this code!
// Ugly implementation!
object GetLines {
def main(args: Array[String]) {
if (args.length < 1) {
println("Please specify the file to count")
return
}
// Prirequisite
val dict = Map[String, BitSet]()
// read lines
var lineCount = 0
for (line <- io.Source.fromFile(args(0),"Unicode").getLines) {
// Parse line
val tokens = line.split("\t")
val code = tokens(0).toString
if (code != "CODE") { // Remove header
val floored_serial = tokens(1).toDouble.toInt
// Add/Update dict
if (dict.keySet.contains(code)) {
var bs = dict(code)
bs += floored_serial
} else {
var bs = BitSet(floored_serial)
dict.put(code, bs)
}
}
}
println(dict.values.foldLeft(0)(_ + _.size))
}
}
Main-Class: GetLines
Class-Path: scala-library.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment