亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? huf.c

?? 霍夫曼算法編碼、解壓encodedecode
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*******************************************************************************
*                                                                              *
* HUF.C   by Shaun Case   April 1991                                           *
*                                                                              *
* Written in Borland C++ 2.0 under MS-DOS 3.3                                  *
*                                                                              *
* Uses Huffman encoding to compress a single file.                             *
* This program is in the public domain.                                        *
*                                                                              *
* atman%ecst.csuchico.edu@RELAY.CS.NET                                         *
*                                                                              *
*                                                                              *
*******************************************************************************/

#include <stdio.h>
#include <math.h>
#include <dir.h>                        /* for storing filename in output file      */

#define FALSE 0                         /* i'm still deciding on a style...         */
#define TRUE !FALSE

/*
 * for lots of interesting (?) diagnostics, uncomment the following:
#define VERBOSE
 *
 */


typedef struct chardata {               /* template for leaves and nodes in tree    */
    short charnum;                      /* which character to be encoded            */
                                        /* don't want it lost in the sort           */
    unsigned long total;                /* total occurances in the file             */
    short seq_length;                   /* length of this char's huffman code (bits)*/
    short bit_sequence;                 /* the huffman code sequence for this char  */
    double frequency;                   /* frequency of occurance, < 1.0            */
    struct chardata *up, *left, *right; /* pointers to rest of tree                 */
};

typedef struct decode_table_element {   /* template for decode table element (wow)  */
    unsigned char letter;               /* which character to decode to             */
    char spare;                         /* force 16-bit word alignment              */
    short left;                         /* index of lower left element from tree    */
    short right;                        /* index of lower right element from tree   */
};


int compare(const void*, const void*);  /* prototype for compare() for qsort()      */

struct chardata *huftable[256];         /* array that points to leaves in tree      */
struct chardata *root=NULL;             /* future root of tree                      */
struct decode_table_element *decode_table;  /* pointer to decode table              */
short array_max_index=0;                /* max number of elements in array (to be   */
                                        /* determined in create_decode_table()      */

long real_bit_total=0L;
double avg_bits_per_symbol=0;           /* averages num of bits needed to represent */
unsigned long  total;                   /* total number of unencoded bytes          */
long real_bits_total = 0L;
FILE *infile;                           /* file ptr to original file (uncompressed) */
FILE *outfile;                          /* file ptr to output fiel   (compressed)   */
char *infile_name;                      /* ptr to name of input file                */
char *outfile_name;                     /* ptr to name of output file               */


int main(int argc, char **argv)
{

#ifdef VERBOSE
    void show_encode_info(void);                    /* prototype   */
    void show_encoded_file_size(void);              /* prototype   */
    void show_decode_table(void);                   /* prototype   */
#endif

    void dumptable(void);                           /* prototype   */
    short create_tree(void);                        /* prototype   */
    void gen_bit_sequences(struct chardata *node);  /* prototype   */
    short create_decode_table(void);                /* prototype   */
    short compress(void);                           /* prototype   */

    register short c;                               /* a character */
	
    if (argc != 3) {                                /* check command line arguments */
        puts("'huf file1 file2' encodes file1 into file2.");
        return 1;
	}
    puts("Huf by Shaun Case, 1991, Public Domain");
    infile_name = argv[1];
    outfile_name = argv[2];

    puts("Analyzing data.");

    for (c=0; c < 256; c++)                         /* initialize decode table      */
    {
        if ((huftable[c] = (struct chardata *)malloc(sizeof (struct chardata)))== NULL)
        {
            printf("Unable to allocate space for %dth huftable node.",c);
            return 1;
        }
        huftable[c]->charnum   = c;                 /* need to know who we are after qsort() gets done with us */
        huftable[c]->total     = 0L;
        huftable[c]->frequency = 0;
        huftable[c]->up        = NULL;
        huftable[c]->left      = NULL;
        huftable[c]->right     = NULL;
    }


    if ((infile=fopen(infile_name, "rb")) == NULL)  /* open the input file              */
    {
        printf("Unable to open %s.\n", infile_name);
        return 1;
    }

    while (!feof(infile))                           /* get character distribution data  */
    {
        c = fgetc(infile);

        if (feof(infile))
            continue;

        ++total;
        ++huftable[c]->total;                       /* increment total for char c       */
    }

    if (total == 0L)                                /* handle empty file                */
    {
        puts("Input file is empty, aborting.");
        return 0;
    }

    fclose(infile);
                                                    /* sort according to frequency of occurance */

    qsort((void *)huftable, (size_t)256, (size_t)sizeof(struct chardata *),
        compare);

    dumptable();                                    /* fill huftable with distribution freqs    */

    if (create_tree() != TRUE)                      /* make the huffman tree (bit sequences)    */
        return 1;

#ifdef VERBOSE
    printf("\nFreq of root is %f.\n",root->frequency);  /* this should be 1.0 if all went well  */

    puts("\nBit sequences:\n\n");
#endif

    avg_bits_per_symbol = 0;
    gen_bit_sequences(root);                        /* build bit sequences, stuff seqs &        */
                                                    /* lengths into associated leaves           */

#ifdef VERBOSE
    printf("\n\nActual bits per symbol = %f", avg_bits_per_symbol);
    printf("\nActual final data size w/o table should be %f\n",
        avg_bits_per_symbol * (double)total / ((double) 8));

    show_encoded_file_size();
#endif

    puts("Building decode table...");
    if (create_decode_table() != TRUE)              /* create decode array from tree            */
    {
        puts("Unable to allocate space for decode table, exiting.");
        return 1;
    }

    printf("Decode table built, contains %d elements.\n",array_max_index + 1);

#ifdef VERBOSE
    show_decode_table();
    show_encode_info();
#endif

    if (compress() != 0)                            /* now that we have all necessary info,     */
        return 1;                                   /* perform the compression.                 */

    puts("Done.");
    return 0;

}

/*****************************************************************************
 * this code is going to be a little strange -- we have an array of items    *
 * that are going to be the leaves of the tree, and we have to go upward     *
 * linking them together to make the root.  For algorithm, see my notebook,  *
 * or look up huffman compression in a good algorithms book, or see          *
 * huffman's paper -- "A Method for the Construction of Minimum-Redundancy   *
 * Codes" David A. Huffman, Proceedings of the IRE 40, 1098-- 1101           *
 *                                                                           *
 * after the tree is built, the root of the tree is assigned to the global   *
 * variable root.                                                            *
 *                                                                           *
 * -- Shaun Case                                                             *
 *****************************************************************************/

struct chardata *ptr1, *ptr2;          /* 1 = smallest freq, 2 = 2nd smallest */

short create_tree()
{
    void find_lowest_freqs(void);      /* prototype */
    short only_one_up_ptr_left(void);  /* prototype */


    double maxfreq = 0 ;               /* max combined freqency in the tree   */
    struct chardata *new_node = NULL;  /* ptr to new node to be created       */

    puts("Creating tree from frequencies...");

    while (maxfreq < 0.99999 )         /* while we haven't made the root yet  */
    {
        find_lowest_freqs();           /* find the two lowest combined or     */
                                       /*   unused single frequencies         */

        if (                           /* create a new node                   */
            (new_node = (struct chardata *)malloc(sizeof (struct chardata)) )
            == NULL
           )
        {
            puts("Insufficient memory, malloc() failed in create_tree().");
            return FALSE;
        }
                                        /* initialize the new node            */
        new_node->up    = NULL;
        new_node->left  = ptr2;
        new_node->right = ptr1;
        new_node->charnum = -1; /* if you get a lot of -1s when traversing the tree, */
                                /* you aren't looking at the leaves.                 */
        ptr1->up = new_node;
        ptr2->up = new_node;

        new_node->frequency = ptr1->frequency + ptr2->frequency; /* combine 2 old freqs */

        maxfreq = new_node->frequency;  /* clever optimization */
#ifdef VERBOSE
        printf("Newly created freq == %f\n", maxfreq);
#endif
    }

    root = new_node;                    /* update global variable   */

    if (only_one_up_ptr_left())         /* verify tree is correct   */
    {                                   /* algorirthm seems to work */
        puts("Done creating tree.");    /*  fine, this is a saftey  */
#ifdef verbose                          /*  check.                  */
        puts("Win: apparently only one remaining up-pointer.");
#endif
    }
    else
    {
        puts("Lose: apparently more than one remaining up-pointer.");
        return FALSE;
    }

    return TRUE;                        /* everything is fine.      */
}


/************************************************************
 * verify there is only one root after the tree is created  *
 * by making sure only one node has an up pointer that has  *
 * the value NULL.                                          *
 *                                                          *
 * Just a double-check.                                     *
 *                                                          *
 ************************************************************/

short only_one_up_ptr_left(void)
{
    short bottom=255;
    register struct chardata *tptr;
    register struct chardata *first_null_up_ptr=NULL;

    tptr=huftable[bottom];

    while (bottom != -1)
    {
        while (tptr->up != NULL)            /* find root for this leaf       */
            tptr = tptr->up;

        if (first_null_up_ptr == NULL)      /* assign uptr to root, 1st time */
            first_null_up_ptr = tptr;
        else
            if (first_null_up_ptr != tptr)  /* uh oh, found another root..   */
                return FALSE;

        --bottom;
    }

    return TRUE;
}

/****************************************************************
 *                                                              *
 * Find the two smallest combined or unused single frequencies  *
 * in the partially-constructed tree.                           *
 *                                                              *
 ****************************************************************/

void find_lowest_freqs(void)
{
    register struct chardata *tptr;

    /* the following are local for speed (I think double indirection is slow */

    register struct chardata *local_minptr;         /* ptr to smallest unused freq     */
    register struct chardata *local_second_minptr;  /* ptr to 2nd smallest unused freq */

    struct chardata dummy;
    short bottom = 255;

    dummy.frequency = 2.0;          /* initialize to bigger than 1.000         */
    local_minptr=&dummy;            /* initialize to bigger than 1.000         */

    while(bottom != -1)             /* find smallest "unused" frequency of all */
    {
        tptr = huftable[bottom];

        if (tptr->total == 0L)      /* skip unused byte values (not all files  */
        {                           /* contain all 256 chars)                  */
            --bottom;
            continue;
        }

        while (tptr->up != NULL)    /* find top of tree ending in current leaf */
            tptr = tptr->up;

        if (tptr->frequency < local_minptr->frequency)  /* if current < min    */
            local_minptr = tptr;                        /* then min = current  */

        --bottom;                   /* keep going... */
    }

    /* now find second smallest "unused" frequency   */


    bottom = 255;                   /* start at the bottom again */
    local_second_minptr=&dummy;     /* initialize to bigger than 1.000         */

    while(bottom != -1)
    {
        tptr = huftable[bottom];

        if (tptr->total == 0L)      /* skip unused byte values                 */
        {
            --bottom;
            continue;
        }

        while (tptr->up != NULL)    /* find top of tree ending in current leaf */
            tptr = tptr->up;

        if (
             (tptr->frequency < local_second_minptr->frequency)  /* if current < min2    */
             && (tptr != local_minptr)                           /* and curr <> min1     */
           )
           local_second_minptr = tptr;                           /* then min2 = current  */

        --bottom;                   /* keep going... */
    }

    ptr1 = local_minptr;
    ptr2 = local_second_minptr;

}


/*******************************************************
 *                                                     *
 * Dump the contents of the huffman table.             *
 * also fills huftable with distribution frequencies   *
 *                                                     *
 *******************************************************/


void dumptable(void)
{
    register short i;
    int bits_per_char;
    double check_total = 0;
    double percent     = 0;
    double frac;

#ifdef VERBOSE
    puts("Totals:\n");
#endif

#ifdef VERBOSE
    printf("\n\ntotal chars = %ld.\n", total );
#endif

    if (total==0)   /* otherwise get divide by zero error */
        return;

    avg_bits_per_symbol=0;
    for (i=0; i< (256); i++)
    {
        huftable[i]->frequency = frac = (((double)huftable[i]->total))/(double)total;
        percent= (double)(100)*frac;
        if (frac >0)
            bits_per_char = (int)ceil( -log10(frac)/log10((double)2));

#ifdef VERBOSE
        printf("\n%3d = %6ld = %%%6.3f => %d bits",huftable[i]->charnum,
            huftable[i]->total, percent,
            bits_per_char );
#endif

        check_total += percent;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av电影在线观看完整版一区二区| 欧洲另类一二三四区| 日韩美一区二区三区| 亚洲福利视频三区| 日本韩国一区二区| 亚洲一区欧美一区| 91高清视频在线| 亚洲一区在线观看免费观看电影高清 | 国产欧美一区二区精品性色超碰| 美腿丝袜一区二区三区| 日韩午夜小视频| 热久久一区二区| 欧美一区二区二区| 老司机精品视频在线| 欧美videos中文字幕| 久久99精品久久久久久国产越南 | 欧美大片一区二区三区| 九九九精品视频| 欧美电视剧在线看免费| 国产一区美女在线| 国产欧美一二三区| 99国产精品国产精品毛片| 亚洲欧美日韩久久| 在线观看免费亚洲| 日日骚欧美日韩| 日韩你懂的电影在线观看| 国产一区二区主播在线| 日本一区二区视频在线| 99v久久综合狠狠综合久久| 一区二区三区四区亚洲| 777午夜精品免费视频| 日韩av一级电影| 精品成人佐山爱一区二区| 国产黄人亚洲片| 亚洲精品老司机| 在线不卡一区二区| 国产综合久久久久久鬼色| 国产欧美精品一区二区色综合朱莉| 99在线精品观看| 亚洲第一电影网| 日韩欧美国产电影| 成人性视频免费网站| 亚洲卡通动漫在线| 7777女厕盗摄久久久| 国产一区二区免费在线| 亚洲人成在线播放网站岛国| 欧美日韩国产精选| 国内精品视频666| 中文字幕一区在线观看视频| 欧美日产国产精品| 国产在线精品视频| 亚洲三级电影网站| 91精品国产乱码久久蜜臀| 国产精品亚洲а∨天堂免在线| 中文字幕中文字幕一区| 欧美日韩一区二区欧美激情 | 日韩精品福利网| 国产午夜亚洲精品羞羞网站| 色综合天天综合狠狠| 日本不卡视频在线| 国产精品免费免费| 9191久久久久久久久久久| 国产精品亚洲午夜一区二区三区 | 麻豆精品在线看| 日韩一区有码在线| 5566中文字幕一区二区电影| 风间由美中文字幕在线看视频国产欧美| 一级精品视频在线观看宜春院| 日韩精品一区二区三区在线| 91在线丨porny丨国产| 免费高清成人在线| 亚洲欧美福利一区二区| 欧美va亚洲va| 欧美性猛交xxxxxx富婆| 国产激情精品久久久第一区二区 | 亚洲欧洲另类国产综合| 91精品国产91久久久久久一区二区 | 欧美国产1区2区| 91精品国产91综合久久蜜臀| 91在线视频观看| 国内精品久久久久影院薰衣草| 亚洲自拍偷拍九九九| 国产日韩在线不卡| 日韩午夜在线观看| 欧美系列日韩一区| eeuss鲁一区二区三区| 久久精品国产成人一区二区三区| 亚洲免费伊人电影| 国产亚洲制服色| 欧美一级理论性理论a| 91黄色免费网站| 波多野结衣中文字幕一区二区三区 | 精品一区二区三区在线视频| 亚洲综合在线五月| 国产欧美一区二区三区沐欲| 日韩一级片在线观看| 91国偷自产一区二区三区观看| 成人免费观看视频| 国产一区二区三区四区五区美女| 亚洲va在线va天堂| 玉米视频成人免费看| 国产精品午夜春色av| www国产成人免费观看视频 深夜成人网| 欧美日韩一级大片网址| 91麻豆视频网站| 成人国产在线观看| 国产成人小视频| 国产麻豆一精品一av一免费| 秋霞影院一区二区| 日韩不卡手机在线v区| 天天色天天爱天天射综合| 亚洲综合男人的天堂| 亚洲精品视频免费看| 成人免费在线视频观看| 中文字幕久久午夜不卡| 国产日韩欧美电影| 久久亚洲精品国产精品紫薇| 欧美一区二区三区的| 欧美精选一区二区| 欧美日韩一级片在线观看| 欧美亚洲丝袜传媒另类| 在线视频国内一区二区| 色综合天天综合色综合av| 色综合色综合色综合色综合色综合| 成人影视亚洲图片在线| 粉嫩av一区二区三区| 成人夜色视频网站在线观看| 丁香婷婷综合激情五月色| 国产成人综合精品三级| 丁香一区二区三区| 成a人片亚洲日本久久| 97se亚洲国产综合自在线观| 色综合久久综合网97色综合| 91国产免费看| 欧美日韩mp4| 日韩一卡二卡三卡| 2017欧美狠狠色| 国产婷婷色一区二区三区| 国产欧美久久久精品影院| 国产精品麻豆久久久| 亚洲欧美一区二区视频| 亚洲精品免费播放| 午夜欧美在线一二页| 免费在线观看一区| 韩国女主播成人在线观看| 国产盗摄精品一区二区三区在线 | 欧美一二区视频| 欧美成人艳星乳罩| 久久精品亚洲麻豆av一区二区 | 国模无码大尺度一区二区三区| 国内久久婷婷综合| 成人综合日日夜夜| 91视频你懂的| 欧美在线小视频| 欧美一区二区三区婷婷月色| 精品国产乱码久久久久久蜜臀| 精品国产污污免费网站入口 | 国产一区二区不卡在线 | va亚洲va日韩不卡在线观看| 色综合天天综合在线视频| 欧美日韩午夜在线视频| 日韩一区二区在线观看视频播放| 精品裸体舞一区二区三区| 国产精品久久久久永久免费观看 | 中文字幕一区二区三区在线观看| 亚洲天堂2014| 日韩精品福利网| 国产精品一区二区果冻传媒| 色视频欧美一区二区三区| 在线播放一区二区三区| 久久精品一区二区三区四区| 亚洲女同ⅹxx女同tv| 五月天精品一区二区三区| 精品一区二区三区在线播放视频| 99综合电影在线视频| 6080yy午夜一二三区久久| 国产丝袜欧美中文另类| 亚洲高清视频在线| 激情欧美一区二区三区在线观看| www.成人在线| 日韩三级免费观看| 国产精品超碰97尤物18| 日本成人在线电影网| 成人免费av在线| 欧美精品在线观看播放| 亚洲国产精品成人久久综合一区 | 亚洲欧洲中文日韩久久av乱码| 日本伊人精品一区二区三区观看方式| 国产伦精品一区二区三区在线观看| 91色乱码一区二区三区| 日韩精品一区二区三区中文精品 | 亚洲女同一区二区| 精品一区二区在线视频| 日本二三区不卡| 国产亚洲综合在线| 日本伊人精品一区二区三区观看方式| 成人免费视频app| 日韩女优av电影在线观看| 一区二区三区在线不卡| 国产99久久久国产精品潘金网站|