开发者

Questions about custom Deflate implementation in C#

开发者 https://www.devze.com 2023-03-21 09:22 出处:网络
I am currently working on a custom deflate algorithm that should be encapsulated in a custom class derriving from System.IO.Stream.

I am currently working on a custom deflate algorithm that should be encapsulated in a custom class derriving from System.IO.Stream.

I know there is a .Net implementation of a DeflateStream, but I as well want to as well completely understand the algorithm as need to implement it because Silverlight what I am using doesn't include that class.

I already read some information about deflate und understand that deflate is a combination of LZ77 and Huffman-Encoding and already spent some time for the LZ77 implementation but now do have a few questions about it:

1) The output of LZ77 is a list of triplets (offset, length, successor). It isn't quite efficient to map them as three bytes, isn't it? What would you suggest? I an writing all output to an underlying MemoryStream which is only able to handle (a set of) bytes.

2) What size would you suggest to use for the sliding window?

3) I do know what Huffman coding is, but how do I apply it here? My pr开发者_开发知识库oblem is that I don't know what size of "chunks" I need to map with it and didn't find any information about this. Do I apply it for each byte? Two bytes? Three? And how do I handle the resulting output (same problem as mentionend in 1))? I thought about using a kind of state machine that continues reading bytes and extracting the Huffman codes, but this doesn't seem to be very efficient. Is there a better way?

Thank you in advance!


Can't tell you for the first 2 points, but Huffman coding is basically about generating binary codes for each symbol in your sequence. Code length depends on how frequent the symbol is. The shorter codes are for populars and the longer ones are for unpopulars. The idea is like:

abaaaaaaaaaabaaaaaaaabaaaaaaaaaaaaaa

  1. Use 1 for 'a'
  2. Use 01 for 'b'
0

精彩评论

暂无评论...
验证码 换一张
取 消