Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve method seekBlock #1

Open
jasonwee opened this issue Jul 23, 2014 · 0 comments
Open

improve method seekBlock #1

jasonwee opened this issue Jul 23, 2014 · 0 comments

Comments

@jasonwee
Copy link
Collaborator

TODO if big loop over big file pointer, may not be efficient, consider jump to the nearest file block. https://github.com/Opentracker/luceneOnCassandra/blob/master/src/main/java/org/apache/lucene/cassandra/FileDescriptorUtils.java

long jumpBlocksSize = 0;

long newWhichBlock = filePointer / descriptor.getBlockSize();  
if ( newWhichBlock > 0) {
        System.out.println("using new seek");
        int start = (int) --newWhichBlock;
        jumpBlocksSize = descriptor.getBlockSize() * start;
        System.out.println("start " + start + " jumpBlocksSize " + jumpBlocksSize);
        for (int i = start; i <= descriptor.getBlocks().size(); i++) {
            System.out.println("loop " + i);
            FileBlock fb = descriptor.getBlocks().get(i);
            jumpBlocksSize += fb.getDataLength();
            if (filePointer < jumpBlocksSize) {
                fb.setBlockOffset(jumpBlocksSize - fb.getDataLength());
                fb.setDataPosition((int) (filePointer - fb.getBlockOffset()));
                System.out.println("hit and return block " + fb.getBlockNumber());
                return fb;
            }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant