throw new IllegalArgumentException(); final int[] length = decoderInputs.getLengths();
throw new IllegalArgumentException(); final int[] length = decoderInputs.getLengths();
.getShortestCodeWord(), actualInputs.getShortestCodeWord()); assertEquals("length[]", decoderInputs.getLengths(), actualInputs .getLengths());
decoderInputs.getLengths(), decoderInputs .getSymbols()); } else {
decoderInputs.getLengths(), decoderInputs .getSymbols()); } else {
decoderInputs.getLengths(), decoderInputs.getSymbols());
decoderInputs.getLengths(), decoderInputs.getSymbols());
.getShortestCodeWord(), actualInputs.getShortestCodeWord()); assertEquals("length[]", decoderInputs.getLengths(), actualInputs .getLengths());
/** * 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()); }
/** * 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()); }
/** * 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)); } }
/** * 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)); } }
/** * 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()); }
/** * (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()); }
/** * (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()); }