-2

I have huffman and lz77 codes, but I need any way to merge this algorithms to make deflate

How i can do this?

I have to write it manually without using libraries.

Boken
  • 4,825
  • 10
  • 32
  • 42
  • 2
    Could you please add your code as well? – verity Jul 15 '20 at 19:42
  • 1
    By "code" do you mean the encoding of numbers, or source code? Do you know a bit how Deflate is working? – Zerte Jul 15 '20 at 20:39
  • @Zerte : I did not understand your purpose well .. But I worked on creating a Hoffman tree and then created lz77..I now want to try to combine the two algorithms in order to create a deflate..I don’t know exactly how it works because I have not found anyone to explain the algorithm well on the Internet and I don’t want to use Libraries – Mohamad1299 Jul 16 '20 at 09:11
  • 1
    The deflate algorithm/format is [documented](https://tools.ietf.org/html/rfc1951). – 500 - Internal Server Error Jul 16 '20 at 09:37

1 Answers1

1

LZ77 gives you a sequence of literal and length/distance pairs. There are many ways to apply Huffman coding to that. The first step would be to apply Huffman coding to the literals, as if there were no LZ77. Then just pass the length/distance pairs through as is, making sure you can tell whether the next thing is a literal or a length/distance pair.

After that you can also try to code the length/distance pairs. Deflate puts the literals and lengths in a single Huffman code, and the distances in a second Huffman code. Or you could code a count of literals that are followed by one length, then put the literals and length in different Huffman codes. Or ... many other ways.

In order to be able to decode, you also need to describe the Huffman codes you use at the start of the stream.

You can read the deflate description for how it does all that.

Community
  • 1
  • 1
Mark Adler
  • 101,978
  • 13
  • 118
  • 158