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

exception when compress. #13

Closed
jcai opened this issue Sep 9, 2013 · 4 comments
Closed

exception when compress. #13

jcai opened this issue Sep 9, 2013 · 4 comments

Comments

@jcai
Copy link

jcai commented Sep 9, 2013

int data = new int[]{1,200000000};

IntegratedIntegerCODEC codec = new
IntegratedComposition(
new IntegratedBinaryPacking(),
new IntegratedVariableByte());
// output vector should be large enough...
int [] compressed = new int[data.length];
// compressed might not be large enough in some cases
// if you get java.lang.ArrayIndexOutOfBoundsException, try
// allocating more memory

    /**
    *
    * compressing
    *
    */
    IntWrapper inputoffset = new IntWrapper(0);
    IntWrapper outputoffset = new IntWrapper(0);
    codec.compress(data,inputoffset,data.length,compressed,outputoffset);
    // got it! 
    // inputoffset should be at data.length but outputoffset tells
    // us where we are...
    System.out.println("compressed from "+data.length*4/1024+"KB to "+outputoffset.intValue()*4/1024+"KB");
    // we can repack the data: (optional)
    compressed = Arrays.copyOf(compressed,outputoffset.intValue());
@jcai
Copy link
Author

jcai commented Sep 9, 2013

java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkBounds(Buffer.java:535)
at java.nio.DirectIntBufferS.get(DirectIntBufferS.java:254)
at me.lemire.integercompression.IntegratedVariableByte.compress(IntegratedVariableByte.java:40)
at me.lemire.integercompression.IntegratedComposition.compress(IntegratedComposition.java:45)

@koron
Copy link
Collaborator

koron commented Sep 9, 2013

@jcai

Please try to extend length of compressed like this

int [] compressed = new int[data.length + 32];

It is known that VariableByte#compress requirs longer array when original array is too short.

@koron
Copy link
Collaborator

koron commented Sep 9, 2013

It was mentioned in #11

@lemire
Copy link
Owner

lemire commented Sep 9, 2013

I'm closing this. Please reopen if you disagree.

It is clearly stated in your example that "if you get java.lang.ArrayIndexOutOfBoundsException, try allocating more memory". You do get ArrayIndexOutOfBoundsException and so, the fix is to allocate more memory (as explained by @koron).

@lemire lemire closed this as completed Sep 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants