Skip to content

Commit

Permalink
Use array for run lenght decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
abradle committed Aug 9, 2016
1 parent 48caa79 commit 10cc873
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mmtf-codec/src/main/java/org/rcsb/mmtf/decoder/ArrayDecoders.java
Expand Up @@ -33,15 +33,21 @@ public static int[] deltaDecode(int[] intArray) {
* @return the decoded integer array
*/
public static int[] runlengthDecode(int[] integerArray) {
// We don't know the length so need a List
List<Integer> outList = new ArrayList<>();
// Calculate the length
int totCount =0;
for(int i=0; i<integerArray.length;i+=2){
totCount+=integerArray[i+1];
}
int[] outArray = new int[totCount];
int index = 0;
for (int i=0; i<integerArray.length; i+=2) {
int currentInt = integerArray[i];
int currentCount = integerArray[i+1];
for (int j=0; j<currentCount;j++){
outList.add(currentInt);
outArray[index] = currentInt;
index++;
}
}
return CodecUtils.convertToIntArray(outList);
return outArray;
}
}

0 comments on commit 10cc873

Please sign in to comment.