Skip to content

Instantly share code, notes, and snippets.

@axiak
Created September 24, 2011 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axiak/1238862 to your computer and use it in GitHub Desktop.
Save axiak/1238862 to your computer and use it in GitHub Desktop.
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