Huffman Compression Algorithm

I implemented file compression using the huffman algorithm, but the problem is that to enable decompression of the compressed file, the encoding tree used, or the codes themselves, it should also be written to the file. The question is: how do I do this? What is the best way to write a coding tree at the beginning of a compressed file?

+3
source share
9 answers

There's a fairly standard implementation of Huffman coding in the Basic Compression Library (BCL) , including a recursive function that writes a tree to a file. Look at huffman.C. It just writes the leaves so that the decoder can restore the same tree.

BCL is also good because there are other fairly simple compression algorithms. This is very convenient if you need to flip your own algorithm.

+5
source

First, have you considered using a standard compression stream (e.g. GZipStream in .net)?

, / , Streams Seek ( ). , . , , . .., , , , , .

+3

, 8- (.. ), , , . , , 0, 1,..., 255. . , (, , 4 , 1kb).

, , , 0..255 (0 = ,...), 256 . . ( , 759707 - . )

P.S.: , , seek() .

+2

huffman. . : shcodec. ( ), - .

+2

, , , , .

+1

256 .

+1

node , , node . 8 node.

. :

    /\
   /\ A
  B /\
   C  D

001 [B] 01 [C] 1 [D] 1 [A]

(, huffman.c, , , ).

+1

. . , . , , , , , , , . , .

0

? , , tress.

0
source

Source: https://habr.com/ru/post/1708976/


All Articles