Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Project Tool

Rate me:
Please Sign up or sign in to vote.
4.69/5 (10 votes)
23 Sep 2007CPOL3 min read 54.5K   1.7K   73  
Backup your C# solution and projects for archive or source code sharing. Temporary or unused files are excluded.
using System;
using System.Collections.Generic;
using System.Text;

namespace QiHe.CodeLib.Compress.DeflateFormat
{
    public partial class HuffmanCodes
    {
        HuffmanTree AlphabetHuffmanCode;
        HuffmanTree DistanceHuffmanCode;

        public HuffmanCodes(int[] alphabetCodeLengths, int[] distanceCodeLengths)
        {
            AlphabetHuffmanCode = HuffmanTree.FromCodeLengths(alphabetCodeLengths);
            DistanceHuffmanCode = HuffmanTree.FromCodeLengths(distanceCodeLengths);
        }

        public static readonly HuffmanCodes Default = CreateDefaultCodes();

        private static HuffmanCodes CreateDefaultCodes()
        {
            int[] alphabetCodeLengths = new int[288];
            for (int n = 0; n < 144; n++)
            {
                alphabetCodeLengths[n] = 8;
            }
            for (int n = 144; n < 256; n++)
            {
                alphabetCodeLengths[n] = 9;
            }
            for (int n = 256; n < 280; n++)
            {
                alphabetCodeLengths[n] = 7;
            }
            for (int n = 280; n < 288; n++)
            {
                alphabetCodeLengths[n] = 8;
            }

            int[] distanceCodeLengths = new int[32];
            for (int n = 0; n < 32; n++)
            {
                distanceCodeLengths[n] = 5;
            }

            return new HuffmanCodes(alphabetCodeLengths, distanceCodeLengths);
        }
        
        static readonly int[] CodeLengthOrder = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions