public int decode( final BooleanIterator iterator ) { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = readLong( iterator, lengthIncrement[ curr ] ); for(;;) { if ( x < lastCodeWordPlusOne[ curr ] ) return symbol[ (int)( howManyUpToBlock[ curr ] - lastCodeWordPlusOne[ curr ] + x ) ]; l = lengthIncrement[ ++curr ]; x = x << l | readLong( iterator, l ); } }
/** * This verifies that a code book constructed from a given set of * frequencies may be reconstructed from the cord word bit lengths, given in * a non-decreasing order, together with the symbols in a correlated array. * * @param frequency */ public void doRoundTripTest(final int[] frequency) { final DecoderInputs decoderInputs = new DecoderInputs(); final HuffmanCodec codec = new HuffmanCodec(frequency, decoderInputs); if (log.isDebugEnabled()) { log.debug(printCodeBook(codec.codeWords()) + "\nlength[]=" + Arrays.toString(decoderInputs.getLengths()) + "\nsymbol[]=" + Arrays.toString(decoderInputs.getSymbols())); } final CanonicalFast64CodeWordDecoder actualDecoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs.getSymbols()); for (int i = 0; i < frequency.length; i++) { final BooleanIterator coded = codec.coder().encode(i/*symbol*/); assertEquals(i, actualDecoder.decode(coded)); } }
this.decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs .getSymbols());
/** * This verifies that a code book constructed from a given set of * frequencies may be reconstructed from the cord word bit lengths, given in * a non-decreasing order, together with the symbols in a correlated array. * * @param frequency */ public void doRoundTripTest(final int[] frequency) { final DecoderInputs decoderInputs = new DecoderInputs(); final HuffmanCodec codec = new HuffmanCodec(frequency, decoderInputs); if (log.isDebugEnabled()) { log.debug(printCodeBook(codec.codeWords()) + "\nlength[]=" + Arrays.toString(decoderInputs.getLengths()) + "\nsymbol[]=" + Arrays.toString(decoderInputs.getSymbols())); } final CanonicalFast64CodeWordDecoder actualDecoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs.getSymbols()); for (int i = 0; i < frequency.length; i++) { final BooleanIterator coded = codec.coder().encode(i/*symbol*/); assertEquals(i, actualDecoder.decode(coded)); } }
this.decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs .getSymbols());
final CanonicalFast64CodeWordDecoder actualDecoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs.getSymbols()); assertEquals(value[i]/* symbol */, actualDecoder.decode(ibs));
if (size == 1) codeWord[0] = LongArrayBitVector.getInstance(); coder = new Fast64CodeWordCoder(codeWord, new long[size]); decoder = new CanonicalFast64CodeWordDecoder(new int[size], new int[size]); return; decoder = new CanonicalFast64CodeWordDecoder(length, symbol);
public int decode( final BooleanIterator iterator ) { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = readLong( iterator, lengthIncrement[ curr ] ); for(;;) { if ( x < lastCodeWordPlusOne[ curr ] ) return symbol[ (int)( howManyUpToBlock[ curr ] - lastCodeWordPlusOne[ curr ] + x ) ]; l = lengthIncrement[ ++curr ]; x = x << l | readLong( iterator, l ); } }
final CanonicalFast64CodeWordDecoder actualDecoder = new CanonicalFast64CodeWordDecoder( decoderInputs.getLengths(), decoderInputs.getSymbols()); assertEquals(value[i]/* symbol */, actualDecoder.decode(ibs));
decoderInputs.length = new int[size]; decoderInputs.symbol = new int[size]; decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.length, decoderInputs.symbol ); return; + ", but length[0]=" + length[0]; decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.length, decoderInputs.symbol);
@Override public int decode(final BooleanIterator iterator) { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = readLong(iterator, lengthIncrement[curr]); for(;;) { if (x < lastCodeWordPlusOne[curr]) return symbol[(int)(howManyUpToBlock[curr] - lastCodeWordPlusOne[curr] + x)]; l = lengthIncrement[++curr]; x = x << l | readLong(iterator, l); } }
decoderInputs.length = new int[size]; decoderInputs.symbol = new int[size]; decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.length, decoderInputs.symbol ); return; + ", but length[0]=" + length[0]; decoder = new CanonicalFast64CodeWordDecoder( decoderInputs.length, decoderInputs.symbol);