/** * 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)); } }
/** * @param shortestCodeWord * @param lengths * @param */ private void doCoderRoundTripTest(final BitVector[] expected, final BitVector shortestCodeWord, final int[] length, final int[] symbol) { final PrefixCoder newCoder = HuffmanCodec.newCoder(shortestCodeWord, length, symbol); final BitVector[] actual = newCoder.codeWords(); assertEquals("codeWord[]", expected, actual); if (log.isDebugEnabled()) { log.debug("\nexpected: " + Arrays.toString(expected) + "\nactual : " + Arrays.toString(actual)); } }
/** Creates a new Huffman codec using the given vector of frequencies. * * @param frequency a vector of nonnnegative frequencies. */ public HuffmanCodec(final int[] frequency) { this(intArray2LongArray(frequency)); }
: getSumCodedValueBitLengths(setup.codec().codeWords(), raba, (Byte2Symbol) setup); : new long[size + 1]); final long sumCodedValueBitLengths2 = writeCodedValues(setup .codec().coder(), raba, (Byte2Symbol) setup, codedValueOffset, obs); assert sumCodedValueBitLengths == sumCodedValueBitLengths2 : "sumCodedValueBitLengths=" return new CodedRabaImpl(slice, setup.codec().decoder(), decoderInputsBitLength);
codec = new HuffmanCodec(packedFrequency, decoderInputs); + printCodeBook(codec.codeWords(), this/* Symbol2Byte */));
/** * Unit test for processing an {@link IRaba} representing B+Tree values * suitable to setup the data for compression. * * @throws IOException * * @todo test w/ nulls. */ public void test_valueRabaSetup() throws IOException { final int n = 3; final byte[][] a = new byte[n][]; a[0] = new byte[]{2,3}; a[1] = new byte[]{3,5}; a[2] = new byte[]{'m','i','k','e'}; final IRaba raba = new ReadOnlyValuesRaba(a); final RabaCodingSetup setup = new RabaCodingSetup(raba); // verify that we can re-create the decoder. doDecoderInputRoundTripTest(setup.getSymbolCount(), setup .decoderInputs()); // verify that we can re-create the coder. doCoderRoundTripTest(setup.codec().codeWords(), setup.decoderInputs() .getShortestCodeWord(), setup.decoderInputs().getLengths(), setup.decoderInputs().getSymbols()); }
: getSumCodedValueBitLengths(setup.codec().codeWords(), raba, (Byte2Symbol) setup); : new long[size + 1]); final long sumCodedValueBitLengths2 = writeCodedValues(setup .codec().coder(), raba, (Byte2Symbol) setup, codedValueOffset, obs); assert sumCodedValueBitLengths == sumCodedValueBitLengths2 : "sumCodedValueBitLengths=" return new CodedRabaImpl(slice, setup.codec().decoder(), decoderInputsBitLength);
codec = new HuffmanCodec(packedFrequency, decoderInputs); + printCodeBook(codec.codeWords(), this/* Symbol2Byte */));
/** * Unit test for processing an {@link IRaba} representing B+Tree values * suitable to setup the data for compression. * * @throws IOException * * @todo test w/ nulls. */ public void test_valueRabaSetup() throws IOException { final int n = 3; final byte[][] a = new byte[n][]; a[0] = new byte[]{2,3}; a[1] = new byte[]{3,5}; a[2] = new byte[]{'m','i','k','e'}; final IRaba raba = new ReadOnlyValuesRaba(a); final RabaCodingSetup setup = new RabaCodingSetup(raba); // verify that we can re-create the decoder. doDecoderInputRoundTripTest(setup.getSymbolCount(), setup .decoderInputs()); // verify that we can re-create the coder. doCoderRoundTripTest(setup.codec().codeWords(), setup.decoderInputs() .getShortestCodeWord(), setup.decoderInputs().getLengths(), setup.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)); } }
/** * @param shortestCodeWord * @param lengths * @param */ private void doCoderRoundTripTest(final BitVector[] expected, final BitVector shortestCodeWord, final int[] length, final int[] symbol) { final PrefixCoder newCoder = HuffmanCodec.newCoder(shortestCodeWord, length, symbol); final BitVector[] actual = newCoder.codeWords(); assertEquals("codeWord[]", expected, actual); if (log.isDebugEnabled()) { log.debug("\nexpected: " + Arrays.toString(expected) + "\nactual : " + Arrays.toString(actual)); } }
/** * Unit test for processing an {@link IRaba} representing B+Tree keys * suitable to setup the data for compression. * * @throws IOException */ public void test_keyRabaSetup() throws IOException { final int n = 8; final byte[][] a = new byte[n][]; a[0] = new byte[]{1,2}; a[1] = new byte[]{1,2,3}; a[2] = new byte[]{1,3}; a[3] = new byte[]{1,3,1}; a[4] = new byte[]{1,3,3}; a[5] = new byte[]{1,3,7}; a[6] = new byte[]{1,5}; a[7] = new byte[]{1,6,0}; final IRaba raba = new ReadOnlyKeysRaba(a); final AbstractCodingSetup setup = new RabaCodingSetup(raba); doDecoderInputRoundTripTest(setup.getSymbolCount(), setup .decoderInputs()); // verify that we can re-create the coder. doCoderRoundTripTest(setup.codec().codeWords(), setup.decoderInputs() .getShortestCodeWord(), setup.decoderInputs().getLengths(), setup.decoderInputs().getSymbols()); }
final HuffmanCodec codec = new HuffmanCodec(frequency, decoderInputs); final PrefixCoder expected = codec.coder(); final PrefixCoder actual = new Fast64CodeWordCoder(codec.codeWords()); log.debug(printCodeBook(codec.codeWords()));
/** * (Re-)constructs the canonical huffman code from the shortest code word, * the non-decreasing bit lengths of each code word, and the permutation of * the symbols corresponding to those bit lengths. This information is * necessary and sufficient to reconstruct a canonical huffman code. * * @param decoderInputs * This contains the necessary and sufficient information to * recreate the {@link PrefixCoder}. * * @return A new {@link PrefixCoder} instance for the corresponding * canonical huffman code. */ static public PrefixCoder newCoder(final DecoderInputs decoderInputs) { return newCoder(decoderInputs.getShortestCodeWord(), decoderInputs .getLengths(), decoderInputs.getSymbols()); }
/** * Unit test for processing an {@link IRaba} representing B+Tree keys * suitable to setup the data for compression. * * @throws IOException */ public void test_keyRabaSetup() throws IOException { final int n = 8; final byte[][] a = new byte[n][]; a[0] = new byte[]{1,2}; a[1] = new byte[]{1,2,3}; a[2] = new byte[]{1,3}; a[3] = new byte[]{1,3,1}; a[4] = new byte[]{1,3,3}; a[5] = new byte[]{1,3,7}; a[6] = new byte[]{1,5}; a[7] = new byte[]{1,6,0}; final IRaba raba = new ReadOnlyKeysRaba(a); final AbstractCodingSetup setup = new RabaCodingSetup(raba); doDecoderInputRoundTripTest(setup.getSymbolCount(), setup .decoderInputs()); // verify that we can re-create the coder. doCoderRoundTripTest(setup.codec().codeWords(), setup.decoderInputs() .getShortestCodeWord(), setup.decoderInputs().getLengths(), setup.decoderInputs().getSymbols()); }
final HuffmanCodec codec = new HuffmanCodec(frequency, decoderInputs); final PrefixCoder expected = codec.coder(); final PrefixCoder actual = new Fast64CodeWordCoder(codec.codeWords()); log.debug(printCodeBook(codec.codeWords()));
/** * (Re-)constructs the canonical huffman code from the shortest code word, * the non-decreasing bit lengths of each code word, and the permutation of * the symbols corresponding to those bit lengths. This information is * necessary and sufficient to reconstruct a canonical huffman code. * * @param decoderInputs * This contains the necessary and sufficient information to * recreate the {@link PrefixCoder}. * * @return A new {@link PrefixCoder} instance for the corresponding * canonical huffman code. */ static public PrefixCoder newCoder(final DecoderInputs decoderInputs) { return newCoder(decoderInputs.getShortestCodeWord(), decoderInputs .getLengths(), decoderInputs.getSymbols()); }