public T decode(final BitInputStreamFlexible bitStream) throws ImagingException {
        int position = 0;
        Node<T> node = nodes.get(0);
        while (node.value == null) {
            final int nextBit;
            try {
                nextBit = bitStream.readBits(1);
            } catch (final IOException ioEx) {
                throw new ImagingException("Error reading stream for huffman tree", ioEx);
            }
            if (nextBit == 0) {
                position = (position << 1) + 1;
            } else {
                position = position + 1 << 1;
            }
            if (position >= nodes.size()) {
                throw new ImagingException("Invalid bit pattern");
            }
            node = nodes.get(position);
            if (node.empty) {
                throw new ImagingException("Invalid bit pattern");
            }
        }
        return node.value;
    }
A Huffman tree implemented as 1 array for high locality of reference.
src/main/java/org/apache/commons/imaging/formats/tiff/itu_t4/HuffmanTree.java