1. Check out our companion app, Forums for Android! Download from Google Play

Fast skipping into text asset

Discussion in 'Application Development' started by euclidean, Aug 30, 2010.

  1. euclidean

    euclidean New Member
    Thread Starter
    5

    Aug 30, 2010
    1
    0
    5
    Hey, so, I'm working on a word game for Android and I'm currently trying to optimize my word validation code.

    There are something like 270,000 words in the English language and I need to be able to take a user-inputted word and confirm it is in this list very quickly. My goal is under 50ms.

    I've written a structure that indexes this list first by number of letters, then by first letter, then by every fiftieth word.

    My problem is that after I do this to get the number of bytes to skip in the appropriate word list text file, I call skip(int bytes) on my BufferedReader. Using the Android tracer, I can see that this call takes up 99.7% of the time spent validating a word - up to about 2 seconds in a worst case search. I figure this method is implemented by calling skip(), <bytes> times.

    So I am looking for a way to skip into an asset stream in constant time, like simply moving the read pointer by a specified number of bytes without actually reading.

    Is this even possible, or should I write a script that divides my word lists up into very small files with 50-100 words each?

    Thanks.
     

    Advertisement

  2. I don't think you need to drop the file size down that small, but it would make sense to split it into several files so you're not having to skip a megabyte just to find the word you're looking for. Splitting this into ten files should give you a pretty big performance increase, but you can tweak the number to what works best for you.
     

Share This Page

Loading...