Created
September 24, 2011 02:10
-
-
Save axiak/1238862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Iterator[DayRecord] { | |
var numRecords = 0 | |
var nextRecord = actualNext() | |
def next() = nextRecord match { | |
case Some(x) => { | |
nextRecord = actualNext() | |
x | |
} | |
case _ => throw new NoSuchElementException() | |
} | |
def actualNext() = { | |
try { | |
if (skipAmount > numRecords) | |
for (i <- Range(0, skipAmount - numRecords)) { | |
in.readObject().asInstanceOf[DayRecord] | |
numRecords += 1 | |
} | |
val d = in.readObject().asInstanceOf[DayRecord] | |
numRecords += 1 | |
if (numRecords % 100000 == 0) | |
println("Loaded %d of %d records [%.2f%% done]".format(numRecords, total, numRecords * 100.0 / total)) | |
Some(d) | |
} catch { | |
case e: EOFException => None | |
} | |
} | |
def hasNext = nextRecord match { | |
case None => false | |
case _ => true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment