Labels

Monday, February 28, 2011

Java Input Parser



This is a Fast Input Parser for Java Standard Input.
It's preferred to use this one instead of both Scanner & BufferedReader as your input reader
It's working for many problems and my recent one is UVa - 11631 - Dark Roads
Enjoy :) :)




this parser was implemented by Knightry

3 comments:

  1. why is it preferred to use this one instead of both Scanner & BufferedReader ?

    ReplyDelete
  2. @ Sara : Thanks alot :)
    @ Moustafa :
    This is what I know so far.. correct me if I'm wrong.

    the buffer size in Java's default BufferedReader is around 8000 bytes ( check the implementation here
    http://www.docjar.com/html/api/java/io/BufferedReader.java.html )
    although they say it's cool for most cases unless we need to change it but this is inconsistent with large ( i mean really really large) input dataset that is used in the system test cases in those online judges.
    also there is a great overhead in the fillBuffer() method that is not needed in case of the input format of those problems. that's why most of us get TLE when submitting with ordinary InputStreamReaders and we switch back to C++ to get Accepted with the same algorithm and code details :D
    but of course I believe they were customized to be optimum in most cases as they mention in the JavaDoc here
    http://download.oracle.com/javase/1.4.2/docs/api/java/io/BufferedReader.html

    but this guy avoided so many overhead in the implementation as you can see the difference between them.

    ReplyDelete