huffman-code

problem in saving Huffman Code?

旧街凉风 提交于 2019-12-06 06:10:23
I want to save Huffman codes into a file. How can I do this? I am saving Huffman codes into a string but size of generated file is bigger than Original file. A very simple approach is to write one bit at a time with something like the following: unsigned char acc; // Accumulator of bit waiting to be written int bitcount; // How many bits are aready present in the accumulator // write a single bit (0/1) void writebit(int bit) { acc |= (bit << bitcount); if (++bitcount == 8) { writebyte(acc); acc = 0; bitcount = 0; } } to read back a sigle bit the procedure is symmetrical unsigned char acc; //

Huffman trees for non-binary alphabets?

巧了我就是萌 提交于 2019-12-06 04:10:35
问题 Is there an easy generalization of Huffman coding trees for situations where the resulting alphabet is not binary? For instance, if I wanted to compress some text by writing it out in ternary, I could still build up a prefix-free coding system for each character I as writing out. Would the straightforward generalization of the Huffman construction (using a k-ary tree rather than a binary tree) still work correctly and efficiently? Or does this construction lead to a highly inefficient coding

Canonical huffman encoding algo

隐身守侯 提交于 2019-12-05 20:34:06
Hello I am trying to implement Canonical huffman encoding but i dont understand wiki and google guides, I need explain more abstractly... I tried this: 1. Get list of regular huffman encoding length's codes. like this: A - code: 110, length: 3. B - code: 111, length: 3. C - code: 10, length 2. D - code: 01, length 2. E - code: 00, length 2. I sorting the table by symbol and length like this: C - code: 10, length 2. D - code: 01, length 2. E - code: 00, length 2. A - code: 110, length: 3. B - code: 111, length: 3. now i dont know how to proceed... tnx a lot Throw out the codes you get from the

PNG: deflate and zlib

試著忘記壹切 提交于 2019-12-05 20:02:58
I'm trying to understand compression in PNG - but I seem to find a lot of contradictory information online ... I would like to understand - how is searching done in the LZ77-part: hash table with linked lists? is this defined in deflate? or implemented in zlib? is there a choice of the search method? - can PNG encoders/decoders set some parameters for the compression (strategy, filter, etc.) or is there a default for PNG? - does the LZ77-part do greedy or lazy evaluation? or is this an option too? - and finally: the 2 Huffman trees, are they compressed in a third tree, and all three of them

Optimized order of HTML attributes for compression

為{幸葍}努か 提交于 2019-12-05 18:02:25
问题 I read somewhere that organizing HTML attributes in a certain order can improve the rate of compression for the HTML document. (I think I read this from Google or Yahoo recommendation for faster sites). If I recall correctly, the recommendation was to put the most common attributes first (e.g. id , etc.) then put the rest in alphabetical order. I'm a bit confused by this. For example, if id attributes were put right after every p tag, the id would contain unique values. Thus, the duplicated

Parsing jpeg file, SOS marker

让人想犯罪 __ 提交于 2019-12-05 04:32:56
I'm having problem with parsing jpeg file. When I hit SOS (start of scan) marker, there are few bytes which meaning I don't understand. In picture bellow, after SOS marker, there are 2 bytes for header length (Ls part on the picture). But what the rest of data on picture mean (for example Ns, Cs1 etc....), and where the pure data starts? Cs1 is a components selection index, This refers back to the SOF section (where horizontal and vertical sampling factors are specified) Td1 is the DC table selector for the current component (Cs1) Ta1 is the AC table selector for the current component (Cs1) Ss

Decoding a Huffman code with a dictionary

无人久伴 提交于 2019-12-04 21:24:29
I need to decode a Huffman code I coded with my program using a file containing the translation beetween ASCII and Huffman bits. I have already a dictionary in the progam from "codes" to ASCII like this one: {'01110': '!', '01111': 'B', '10100': 'l', '10110': 'q', '10111': 'y'} I created the function: def huffmanDecode (dictionary, text) : That needs the dictionary and the code. I have tried searching the text for key in the dictionary and using both the replace method form string and the sub from re but neither of them decodes the message properly. for example if the code is: 011111011101110

variations in huffman encoding codewords

被刻印的时光 ゝ 提交于 2019-12-04 20:18:34
I'm trying to solve some huffman coding problems, but I always get different values for the codewords (values not lengths). for example, if the codeword of character 'c' was 100, in my solution it is 101. Here is an example: Character Frequency codeword my solution A 22 00 10 B 12 100 010 C 24 01 11 D 6 1010 0110 E 27 11 00 F 9 1011 0111 Both solutions have the same length for codewords, and there is no codeword that is prefix of another codeword. Does this make my solution valid ? or it has to be only 2 solutions, the optimal one and flipping the bits of the optimal one ? There are 96

Huffman Tree in Java

ぃ、小莉子 提交于 2019-12-04 19:18:00
I have a problem with my Huffman tree code. In the main method I input a String of Symbols and I also input an Integer array containing the frequency of the Symbols. It should print out each Symbol and its Huffman code, but I think its wrong... Here is the code: package huffman; import java.util.*; abstract class HuffmanTree implements Comparable<HuffmanTree> { public final int frequency; // the frequency of this tree public HuffmanTree(int freq) { frequency = freq; } // compares on the frequency public int compareTo(HuffmanTree tree) { return frequency - tree.frequency; } } class HuffmanLeaf

Huffman trees for non-binary alphabets?

烂漫一生 提交于 2019-12-04 12:40:57
Is there an easy generalization of Huffman coding trees for situations where the resulting alphabet is not binary? For instance, if I wanted to compress some text by writing it out in ternary, I could still build up a prefix-free coding system for each character I as writing out. Would the straightforward generalization of the Huffman construction (using a k-ary tree rather than a binary tree) still work correctly and efficiently? Or does this construction lead to a highly inefficient coding scheme? The algorithm still works and it's still simple — in fact Wikipedia has a brief reference to n