huffman-code

Encoding Huffman Tree Scheme [closed]

萝らか妹 提交于 2020-04-16 02:16:09
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 days ago . I am trying to write a function, (codeWords t) , which traverses a Huffman tree (adds #\0 when it goes left, adds #\1 when it goes right...) and returns these values in pairs of the symbol at a leaf along with its associated encoding as a string over the characters #\0 and #\1 . Similar to what this or

Huffman Tree decoding

我怕爱的太早我们不能终老 提交于 2020-01-26 04:58:26
问题 Given a Huffman tree and a stream of bits, return a pair containing (1) the -- string of symbols encoded by the bits (according to the Huffman tree), and -- (2) a Bool indicating whether the output stream contains every bit from the -- input (that is, return False if there were any bits left over). Here is the code, it only returns the first symbol in the tree. What's the problem? data BTree a = Leaf a | Fork (BTree a) (BTree a) deriving (Show, Eq) traT :: BTree a -> BTree a -> [Bool] -> [a]

How do I represent binary numbers in C++ (used for Huffman encoder)?

家住魔仙堡 提交于 2020-01-17 07:50:12
问题 I am writing my own Huffman encoder, and so far I have created the Huffman tree by using a minHeap to pop off the two lowest frequency nodes and make a node that links to them and then pushing the new node back one (lather, rinse, repeat until only one node). So now I have created the tree, but I need to use this tree to assign codes to each character. My problem is I don't know how to store the binary representation of a number in C++. I remember reading that unsigned char is the standard

Java - My Huffman decompression refuses to decompress non-text files (returns empty file)

﹥>﹥吖頭↗ 提交于 2020-01-15 05:00:52
问题 I am able to compress all kinds of files (.jpg, .mp4 etc.) but when I try to decompress these non-text files the program just returns an empty decompressed file... the weird part is that I am able to decompress plain text files just fine. When I compress my original file I put both the data needed to reconstruct the tree and the encoded bits in the same file. The format looks something like this: <n><value 1><frequency 1>...<value n><frequency n>[the compressed bytes] Where n is the total

Predict Huffman compression ratio without constructing the tree

青春壹個敷衍的年華 提交于 2020-01-13 07:03:32
问题 I have a binary file and i know the number of occurrences of every symbol in it. I need to predict the length of compressed file IF i was to compress it using Huffman algorithm. I am only interested in the hypothetical output length and not in the codes for individual symbols, so constructing Huffman tree seems redundant. As an illustration i need to get something like "A binary string of 38 bits which contains 4 a's, 5 b's and 10 c's can be compressed down to 28 bits.", except both the file

Handling last byte in huffman compression/decompression

帅比萌擦擦* 提交于 2020-01-06 08:03:17
问题 I have a program that produces a Huffman tree based on ASCII character frequency read in a text input file. The Huffman codes are stored in a string array of 256 elements, empty string if the character is not read. This program also then encodes and compresses an output file and then is able to take the compressed file as an input file and does decompression and decoding. In summary, my program takes a input file compresses and encodes an output file, closes the output file and opens the

DCT based Video Encoding Process

南笙酒味 提交于 2020-01-06 07:56:12
问题 I am having some issues that I am hoping you will be able to clarify. I have self taught myself a video encoding process similar to Mpeg2. The process is as follows: Split an RGBA image into 4 separate channel data memory blocks. so an array of all R values, a separate array of G values etc. take the array and grab a block of 8x8 pixel data, to transform it using the Discrete Cosine Transform (DCT). Quantize this 8x8 block using a pre-calculated quantization matrix. Zigzag encode the output

Library to compress text data and store it as text

 ̄綄美尐妖づ 提交于 2020-01-05 04:31:08
问题 I want to store web pages in compressed text files (CSV). To achieve the optimal compression, I would like to provide a set of 1000 web pages. The library should then spend some time creating the optimal "dictionary" for this content. One obvious "dictionary" entry could be <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> , which could get stored as %1 or something like that because it is present on almost all web pages. By creating a customized

Huffman Tree Encoding

牧云@^-^@ 提交于 2020-01-05 02:53:27
问题 My Huffman tree which I had asked about earlier has another problem! Here is the code: package huffman; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Scanner; public class Huffman { public ArrayList<Frequency> fileReader(String file) { ArrayList<Frequency> al = new ArrayList<Frequency>(); Scanner s; try { s = new Scanner(new FileReader(file)).useDelimiter(""); while (s.hasNext()) { boolean found =

I don't understand this Huffman algorithm implementation

限于喜欢 提交于 2020-01-03 19:28:53
问题 template<class T> void huffman(MinHeap<TreeNode<T>*> heap, int n) { for(int i=0;i<n-1;i++) { TreeNode<T> *first = heap.pop(); TreeNode<T> *second = heap.pop(); TreeNode<T> *bt = new BinaryTreeNode<T>(first, second, first.data, second.data); heap.push(bt); } } In my Fundamentals of Data Structures in C++ textbook, it gave a 2 page definition of Huffman coding, and the code above. To me, the book wasn't enough detailed, so I've done the googling and I learned how the process of Huffman coding