Skip to content

Commit

Permalink
Minor final review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnbroad committed Feb 27, 2024
1 parent 6ffdb71 commit cccda09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/main/java/htsjdk/samtools/cram/compression/rans/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public static void reverse(final ByteBuffer byteBuffer) {
reverse(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit());
} else {
for (int i = 0; i < byteBuffer.limit(); i++) {
byte tmp = byteBuffer.get(i);
byteBuffer.put(i, byteBuffer.get(byteBuffer.limit() - i - 1));
byteBuffer.put(byteBuffer.limit() - i - 1, byteBuffer.get(i));
byteBuffer.put(byteBuffer.limit() - i - 1, tmp);
}
}
}
Expand Down Expand Up @@ -117,12 +118,14 @@ public static void normaliseFrequenciesOrder1(final int[][] F, final int shift)

// log2 N = Math.log(N)/Math.log(2)
int bitSize = (int) Math.ceil(Math.log(F[Constants.NUMBER_OF_SYMBOLS][j]) / Math.log(2));
if (bitSize > shift)
if (bitSize > shift) {
bitSize = shift;
}

// TODO: check if handling bitSize = 0 is required
if (bitSize == 0)
if (bitSize == 0) {
bitSize = 1; // bitSize cannot be zero
}

// special case -> if a symbol occurs only once and at the end of the input,
// then the order 0 freq table associated with it should have a frequency of 1 for symbol 0
Expand Down Expand Up @@ -152,7 +155,7 @@ public static void normaliseFrequenciesOrder0Shift(final int[] frequencies, fina
// scale the frequencies to (1 << bits) using the calculated shift
for (int symbol = 0; symbol < Constants.NUMBER_OF_SYMBOLS; symbol++) {
if (frequencies[symbol]!=0){
frequencies[symbol] <<= shift;
frequencies[symbol] <<= shift;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public ExternalCompressor getCompressorForMethod(
return getCachedCompressorForMethod(compressionMethod, compressorSpecificArg);

case RANS:
// for efficiency, we want to share the same underlying RANS object with both order-0 and
// order-1 ExternalCompressors
final int ransArg = compressorSpecificArg == ExternalCompressor.NO_COMPRESSION_ARG ?
RANS4x8Params.ORDER.ZERO.ordinal() :
compressorSpecificArg;
Expand Down

0 comments on commit cccda09

Please sign in to comment.