/** Generate the codewords corresponding to this tree decoder. * * @return a vector of codewords for this decoder. */ public BitVector[] buildCodes() { final BitVector[] codeWord = new BitVector[n]; buildCodes(codeWord, root, LongArrayBitVector.getInstance()); return codeWord; }
/** Creates a new codeword-based decoder starting from a set * of complete, lexicographically ordered codewords. It * is responsability of the caller that the tree is well-formed, * that is, that the provided codewords are exactly the root-to-leaf * paths of such a tree. * * @param lexSortedCodeWord a vector of lexically sorted codeWords. * @param symbol a mapping from codewords to symbols. */ public TreeDecoder( BitVector[] lexSortedCodeWord, int[] symbol ) { this( buildTree( lexSortedCodeWord, symbol, 0, 0, lexSortedCodeWord.length ), lexSortedCodeWord.length ); }
decoder = new TreeDecoder(root, size); coder = new CodeWordCoder(decoder.buildCodes());
private static void visit(Node node, final LongArrayBitVector bitVector) { if (node instanceof LeafNode) return; do { bitVector.add(true); visit(node.left, bitVector); bitVector.add(false); } while(! ((node = node.right) instanceof LeafNode)); }
decoder = new TreeDecoder( root, size ); coder = new CodeWordCoder( decoder.buildCodes() );
public LongArrayBitVector succinctRepresentation() { final LongArrayBitVector bitVector = LongArrayBitVector.getInstance(); bitVector.add(true); // Fake open parenthesis if (root != null) visit(root, bitVector); bitVector.add(false); // Fake closed parenthesis bitVector.trim(); return bitVector; } }
decoder = new TreeDecoder( root, size ); coder = new CodeWordCoder( decoder.buildCodes() );
/** Generate the codewords corresponding to this tree decoder. * * @return a vector of codewords for this decoder. */ public BitVector[] buildCodes() { final BitVector[] codeWord = new BitVector[ n ]; buildCodes( codeWord, root, LongArrayBitVector.getInstance() ); return codeWord; } }
/** Creates a new codeword-based decoder starting from a set * of complete, lexicographically ordered codewords. It * is responsibility of the caller that the tree is well-formed, * that is, that the provided codewords are exactly the root-to-leaf * paths of such a tree. * * @param lexSortedCodeWord a vector of lexically sorted codeWords. * @param symbol a mapping from codewords to symbols. */ public TreeDecoder(BitVector[] lexSortedCodeWord, int[] symbol) { this(buildTree(lexSortedCodeWord, symbol, 0, 0, lexSortedCodeWord.length), lexSortedCodeWord.length); }
/** Generate the codewords corresponding to this tree decoder. * * @return a vector of codewords for this decoder. */ public BitVector[] buildCodes() { final BitVector[] codeWord = new BitVector[ n ]; buildCodes( codeWord, root, LongArrayBitVector.getInstance() ); return codeWord; } }
/** Creates a new codeword-based decoder starting from a set * of complete, lexicographically ordered codewords. It * is responsability of the caller that the tree is well-formed, * that is, that the provided codewords are exactly the root-to-leaf * paths of such a tree. * * @param lexSortedCodeWord a vector of lexically sorted codeWords. * @param symbol a mapping from codewords to symbols. */ public TreeDecoder( BitVector[] lexSortedCodeWord, int[] symbol ) { this( buildTree( lexSortedCodeWord, symbol, 0, 0, lexSortedCodeWord.length ), lexSortedCodeWord.length ); }
/** Populates the codeword vector by scanning recursively * the decoding tree. * * @param node a subtree of the decoding tree. * @param prefix the path leading to <code>n</code>. */ private void buildCodes( final BitVector[] codeWord, final TreeDecoder.Node node, final BitVector prefix ) { if ( node instanceof TreeDecoder.LeafNode ) { codeWord[ ((TreeDecoder.LeafNode)node).symbol ] = prefix; return; } BitVector bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); buildCodes( codeWord, node.left, bitVector ); bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); bitVector.set( bitVector.size() - 1 ); buildCodes( codeWord, node.right, bitVector ); }
private static Node buildTree(BitVector lexSortedCodeWords[], final int[] symbol, int prefix, int offset, int length) { if (DEBUG) { System.err.println("****** " + offset + " " + length); System.err.println(Arrays.toString(lexSortedCodeWords)); for(int i = 0; i < length; i++) { System.err.print(lexSortedCodeWords[offset + i].length() + "\t"); for(int j = 0; j < lexSortedCodeWords[offset + i].length(); j++) System.err.print(lexSortedCodeWords[offset + i].getBoolean(j) ? 1 : 0); System.err.println(); } } if (length == 1) return new LeafNode(symbol[offset]); for(int i = length - 1; i-- != 0;) if (lexSortedCodeWords[offset + i].getBoolean(prefix) != lexSortedCodeWords[offset + i + 1].getBoolean(prefix)) { final Node node = new Node(); node.left = buildTree(lexSortedCodeWords, symbol, prefix + 1, offset, i + 1); node.right = buildTree(lexSortedCodeWords, symbol, prefix + 1, offset + i + 1, length - i - 1); return node; } throw new IllegalStateException(); }
/** Populates the codeword vector by scanning recursively * the decoding tree. * * @param node a subtree of the decoding tree. * @param prefix the path leading to <code>n</code>. */ private void buildCodes( final BitVector[] codeWord, final TreeDecoder.Node node, final BitVector prefix ) { if ( node instanceof TreeDecoder.LeafNode ) { codeWord[ ((TreeDecoder.LeafNode)node).symbol ] = prefix; return; } BitVector bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); buildCodes( codeWord, node.left, bitVector ); bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); bitVector.set( bitVector.size() - 1 ); buildCodes( codeWord, node.right, bitVector ); }
private static Node buildTree( BitVector lexSortedCodeWords[], final int[] symbol, int prefix, int offset, int length ) { if ( DEBUG ) { System.err.println( "****** " + offset + " " + length ); System.err.println( Arrays.toString( lexSortedCodeWords ) ); for( int i = 0; i < length; i++ ) { System.err.print( lexSortedCodeWords[ offset + i ].size() + "\t" ); for( int j = 0; j < lexSortedCodeWords[ offset + i ].size(); j++ ) System.err.print( lexSortedCodeWords[ offset + i ].getBoolean( j ) ? 1 : 0 ); System.err.println(); } } if ( length == 1 ) return new LeafNode( symbol[ offset ] ); for( int i = length - 1; i-- != 0; ) if ( lexSortedCodeWords[ offset + i ].get( prefix ) != lexSortedCodeWords[ offset + i + 1 ].get( prefix ) ) { final Node node = new Node(); node.left = buildTree( lexSortedCodeWords, symbol, prefix + 1, offset, i + 1 ); node.right = buildTree( lexSortedCodeWords, symbol, prefix + 1, offset + i + 1, length - i - 1 ); return node; } throw new IllegalStateException(); }
/** Populates the codeword vector by scanning recursively * the decoding tree. * * @param node a subtree of the decoding tree. * @param prefix the path leading to <code>n</code>. */ private void buildCodes(final BitVector[] codeWord, final TreeDecoder.Node node, final BitVector prefix) { if (node instanceof TreeDecoder.LeafNode) { codeWord[((TreeDecoder.LeafNode)node).symbol] = prefix; return; } BitVector bitVector = prefix.copy(); bitVector.length(bitVector.length() + 1); buildCodes(codeWord, node.left, bitVector); bitVector = prefix.copy(); bitVector.length(bitVector.length() + 1); bitVector.set(bitVector.length() - 1); buildCodes(codeWord, node.right, bitVector); }
private static Node buildTree( BitVector lexSortedCodeWords[], final int[] symbol, int prefix, int offset, int length ) { if ( DEBUG ) { System.err.println( "****** " + offset + " " + length ); System.err.println( Arrays.toString( lexSortedCodeWords ) ); for( int i = 0; i < length; i++ ) { System.err.print( lexSortedCodeWords[ offset + i ].size() + "\t" ); for( int j = 0; j < lexSortedCodeWords[ offset + i ].size(); j++ ) System.err.print( lexSortedCodeWords[ offset + i ].getBoolean( j ) ? 1 : 0 ); System.err.println(); } } if ( length == 1 ) return new LeafNode( symbol[ offset ] ); for( int i = length - 1; i-- != 0; ) if ( lexSortedCodeWords[ offset + i ].get( prefix ) != lexSortedCodeWords[ offset + i + 1 ].get( prefix ) ) { final Node node = new Node(); node.left = buildTree( lexSortedCodeWords, symbol, prefix + 1, offset, i + 1 ); node.right = buildTree( lexSortedCodeWords, symbol, prefix + 1, offset + i + 1, length - i - 1 ); return node; } throw new IllegalStateException(); }