@Override public BitVector[] codeWords() { return coder.codeWords(); }
coder = new CodeWordCoder(decoder.buildCodes()); final BitVector[] codeWord = coder.codeWords(); System.err.println("Codes: "); for(int i = 0; i < size; i++)
/** * 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)); } }
coder = new CodeWordCoder( decoder.buildCodes() ); final BitVector[] codeWord = coder.codeWords(); System.err.println( "Codes: " ); for( int i = 0; i < size; i++ )
/** * 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)); } }
coder = new CodeWordCoder( decoder.buildCodes() ); final BitVector[] codeWord = coder.codeWords(); System.err.println( "Codes: " ); for( int i = 0; i < size; i++ )
public BitVector[] codeWords() { return coder.codeWords(); }
public BitVector[] codeWords() { return coder.codeWords(); }
return new Object[] { new HuTuckerCodec( packedFrequency ).coder().codeWords(), char2symbol };
return new Object[] { new HuTuckerCodec( packedFrequency ).coder().codeWords(), char2symbol };
private static Object[] getCoder(final Iterable<? extends CharSequence> iterable, boolean prefixFree) { // First of all, we gather frequencies for all Unicode characters long[] frequency = new long[Character.MAX_VALUE + 1]; int maxWordLength = 0; CharSequence s; int n = 0; for(Iterator<? extends CharSequence> i = iterable.iterator(); i.hasNext();) { s = i.next(); maxWordLength = Math.max(s.length(), maxWordLength); for(int j = s.length(); j-- != 0;) frequency[s.charAt(j)]++; n++; } // Then, we compute the number of actually used characters. We count from the start the stop character. int count = prefixFree ? 1 : 0; for(int i = frequency.length; i-- != 0;) if (frequency[i] != 0) count++; /* Now we remap used characters in f, building at the same time the map from characters to symbols (except for the stop character). */ long[] packedFrequency = new long[count]; final Char2IntMap char2symbol = new Char2IntOpenHashMap(count); for(int i = frequency.length, k = count; i-- != 0;) { if (frequency[i] != 0) { packedFrequency[--k] = frequency[i]; char2symbol.put((char)i, k); } } if (prefixFree) packedFrequency[0] = n; // The stop character appears once in each string. // We now build the coder used to code the strings return new Object[] { new HuTuckerCodec(packedFrequency).coder().codeWords(), char2symbol }; }