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?
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.
First, have you considered using a standard compression stream (e.g. GZipStream in .net)?
, / , Streams Seek ( ). , . , , . .., , , , , .
, 8- (.. ), , , . , , 0, 1,..., 255. . , (, , 4 , 1kb).
, , , 0..255 (0 = ,...), 256 . . ( , 759707 - . )
P.S.: , , seek() .
huffman. . : shcodec. ( ), - .
, , , , .
256 .
node , , node . 8 node.
. :
/\ /\ A B /\ C D
001 [B] 01 [C] 1 [D] 1 [A]
(, huffman.c, , , ).
. . , . , , , , , , , . , .
? , , tress.
Source: https://habr.com/ru/post/1708976/More articles:Overlay and positioning - iphoneCommon php function for multiple forms - databasethe cache counter is not updated, but I can save the parent and child - ruby-on-railsHow to sort a list by property of objects in a collection? - javaStatic member and inheritance - c ++Need a high efficient algorithm to check if a string contains English speech - algorithmThe difference between '#', '%' and '$' - jstlPassing arrays to jQuery plugin - javascriptArrange labels for objects in 2D space without overlapping - layoutbatch file that asks for username / password + registration - loginAll Articles