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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ahuff.c

?? huffman coding and decoding adaptive huffman coding and decoding it is a assignment from my cours
?? C
?? 第 1 頁 / 共 3 頁
字號:
/************************** Start of AHUFF.C ************************* * * This is the adaptive Huffman coding module used in Chapter 4. * Compile with BITIO.C, ERRHAND.C, and either MAIN-C.C or MAIN-E.C */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "bitio.h"#include "errhand.h"char *CompressionName = "Adaptive Huffman coding, with escape codes";char *Usage           = "infile outfile [ -d ]";#define END_OF_STREAM     256#define ESCAPE            257#define SYMBOL_COUNT      258#define NODE_TABLE_COUNT  ( ( SYMBOL_COUNT * 2 ) - 1 )#define ROOT_NODE         0#define MAX_WEIGHT        0x8000#define TRUE              1#define FALSE             0/* * This data structure is all that is needed to maintain an adaptive * Huffman tree for both encoding and decoding.  The leaf array is a * set of indices into the nodes that indicate which node is the * parent of a symbol.  For example, to encode 'A', we would find the * leaf node by way of leaf[ 'A' ].  The next_free_node index is used * to tell which node is the next one in the array that can be used. * Since nodes are allocated when characters are read in for the first * time, this pointer keeps track of where we are in the node array. * Finally, the array of nodes is the actual Huffman tree.  The child * index is either an index pointing to a pair of children, or an * actual symbol value, depending on whether 'child_is_leaf' is true * or false. */typedef struct tree {    int leaf[ SYMBOL_COUNT ];    int next_free_node;    struct node {        unsigned int weight;        int parent;        int child_is_leaf;        int child;    } nodes[ NODE_TABLE_COUNT ];} TREE;/* * The Tree used in this program is a global structure.  Under other * circumstances it could just as well be a dynamically allocated * structure built when needed, since all routines here take a TREE * pointer as an argument. */TREE Tree;/* * Function prototypes for both ANSI C compilers and their K&R brethren. */#ifdef __STDC__void CompressFile( FILE *input, BIT_FILE *output, int argc, char *argv[] );void ExpandFile( BIT_FILE *input, FILE *output, int argc, char *argv[] );void InitializeTree( TREE *tree );void EncodeSymbol( TREE *tree, unsigned int c, BIT_FILE *output );int DecodeSymbol( TREE *tree, BIT_FILE *input );void UpdateModel( TREE *tree, int c );void RebuildTree( TREE *tree );void swap_nodes( TREE *tree, int i, int j );void add_new_node( TREE *tree, int c );void PrintTree( TREE *tree );void print_codes( TREE *tree );void print_code( TREE *tree, int c );void calculate_rows( TREE *tree, int node, int level );int calculate_columns( TREE *tree, int node, int starting_guess );int find_minimum_column( TREE *tree, int node, int max_row );void rescale_columns( int factor );void print_tree( TREE *tree, int first_row, int last_row );void print_connecting_lines( TREE *tree, int row );void print_node_numbers( int row );void print_weights( TREE *tree, int row );void print_symbol( TREE *tree, int row );#elsevoid CompressFile();void ExpandFile();void InitializeTree();void EncodeSymbol();int DecodeSymbol();void UpdateModel();void RebuildTree();void swap_nodes();void add_new_node();void PrintTree();void print_codes();void print_code();void calculate_rows();int calculate_columns();void rescale_columns();void print_tree();void print_connecting_lines();void print_node_numbers();void print_weights();void print_symbol();#endif/* * The high level view of the compression routine is very simple. * First, we initialize the Huffman tree, with just the ESCAPE and * END_OF_STREAM symbols.  Then, we sit in a loop, encoding symbols, * and adding them to the model.  When there are no more characters * to send, the special END_OF_STREAM symbol is encoded.  The decoder * will later be able to use this symbol to know when to quit. * * This routine will accept a single additional argument.  If the user * passes a "-d" argument, the function will dump out the Huffman tree * to stdout when the program is complete.  The code to accomplish this * is thrown in as a bonus., and not documented in the book. */void CompressFile( input, output, argc, argv )FILE *input;BIT_FILE *output;int argc;                char *argv[];{    int c;    InitializeTree( &Tree );    while ( ( c = getc( input ) ) != EOF ) {        EncodeSymbol( &Tree, c, output );        UpdateModel( &Tree, c );    }    EncodeSymbol( &Tree, END_OF_STREAM, output );    while ( argc-- > 0 ) {        if ( strcmp( *argv, "-d" ) == 0 )            PrintTree( &Tree );        else            printf( "Unused argument: %s\n", *argv );        argv++;    }}/* * The Expansion routine looks very much like the compression routine. * It first initializes the Huffman tree, using the same routine as * the compressor did.  It then sits in a loop, decoding characters and * updating the model until it reads in an END_OF_STREAM symbol.  At * that point, it is time to quit. * * This routine will accept a single additional argument.  If the user * passes a "-d" argument, the function will dump out the Huffman tree * to stdout when the program is complete. */void ExpandFile( input, output, argc, argv )BIT_FILE *input;FILE *output;int argc;char *argv[];{    int c;    InitializeTree( &Tree );    while ( ( c = DecodeSymbol( &Tree, input ) ) != END_OF_STREAM ) {        if ( putc( c, output ) == EOF )            fatal_error( "Error writing character" );        UpdateModel( &Tree, c );    }    while ( argc-- > 0 ) {        if ( strcmp( *argv, "-d" ) == 0 )            PrintTree( &Tree );        else            printf( "Unused argument: %s\n", *argv );        argv++;    }}/* * When performing adaptive compression, the Huffman tree starts out * very nearly empty.  The only two symbols present initially are the * ESCAPE symbol and the END_OF_STREAM symbol.  The ESCAPE symbol has to * be included so we can tell the expansion prog that we are transmitting a * previously unseen symbol.  The END_OF_STREAM symbol is here because * it is greater than eight bits, and our ESCAPE sequence only allows for * eight bit symbols following the ESCAPE code. * * In addition to setting up the root node and its two children, this * routine also initializes the leaf array.  The ESCAPE and END_OF_STREAM * leaf elements are the only ones initially defined, the rest of the leaf * elements are set to -1 to show that they aren't present in the * Huffman tree yet. */void InitializeTree( tree )TREE *tree;{    int i;    tree->nodes[ ROOT_NODE ].child             = ROOT_NODE + 1;    tree->nodes[ ROOT_NODE ].child_is_leaf     = FALSE;    tree->nodes[ ROOT_NODE ].weight            = 2;    tree->nodes[ ROOT_NODE ].parent            = -1;    tree->nodes[ ROOT_NODE + 1 ].child         = END_OF_STREAM;    tree->nodes[ ROOT_NODE + 1 ].child_is_leaf = TRUE;    tree->nodes[ ROOT_NODE + 1 ].weight        = 1;    tree->nodes[ ROOT_NODE + 1 ].parent        = ROOT_NODE;    tree->leaf[ END_OF_STREAM ]                = ROOT_NODE + 1;    tree->nodes[ ROOT_NODE + 2 ].child         = ESCAPE;    tree->nodes[ ROOT_NODE + 2 ].child_is_leaf = TRUE;    tree->nodes[ ROOT_NODE + 2 ].weight        = 1;    tree->nodes[ ROOT_NODE + 2 ].parent        = ROOT_NODE;    tree->leaf[ ESCAPE ]                       = ROOT_NODE + 2;    tree->next_free_node                       = ROOT_NODE + 3;    for ( i = 0 ; i < END_OF_STREAM ; i++ )        tree->leaf[ i ] = -1;}/* * This routine is responsible for taking a symbol, and converting * it into the sequence of bits dictated by the Huffman tree.  The * only complication is that we are working are way up from the leaf * to the root, and hence are getting the bits in reverse order.  This * means we have to rack up the bits in an integer and then send them * out after they are all accumulated.  In this version of the program, * we keep our codes in a long integer, so the maximum count is set * to an arbitray limit of 0x8000.  It could be set as high as 65535 * if desired. */void EncodeSymbol( tree, c, output )TREE *tree;unsigned int c;BIT_FILE *output;{    unsigned long code;    unsigned long current_bit;    int code_size;    int current_node;    code = 0;    current_bit = 1;    code_size = 0;    current_node = tree->leaf[ c ];    if ( current_node == -1 )        current_node = tree->leaf[ ESCAPE ];    while ( current_node != ROOT_NODE ) {        if ( ( current_node & 1 ) == 0 )            code |= current_bit;        current_bit <<= 1;        code_size++;        current_node = tree->nodes[ current_node ].parent;    };    OutputBits( output, code, code_size );    if ( tree->leaf[ c ] == -1 ) {        OutputBits( output, (unsigned long) c, 8 );        add_new_node( tree, c );    }}/* * Decoding symbols is easy.  We start at the root node, then go down * the tree until we reach a leaf.  At each node, we decide which * child to take based on the next input bit.  After getting to the * leaf, we check to see if we read in the ESCAPE code.  If we did, * it means that the next symbol is going to come through in the next * eight bits, unencoded.  If that is the case, we read it in here, * and add the new symbol to the table. */int DecodeSymbol( tree, input )TREE *tree;BIT_FILE *input;{    int current_node;    int c;    current_node = ROOT_NODE;    while ( !tree->nodes[ current_node ].child_is_leaf ) {        current_node = tree->nodes[ current_node ].child;        current_node += InputBit( input );    }    c = tree->nodes[ current_node ].child;    if ( c == ESCAPE ) {        c = (int) InputBits( input, 8 );        add_new_node( tree, c );    }    return( c );}/* * UpdateModel is called to increment the count for a given symbol. * After incrementing the symbol, this code has to work its way up * through the parent nodes, incrementing each one of them.  That is * the easy part.  The hard part is that after incrementing each * parent node, we have to check to see if it is now out of the proper * order.  If it is, it has to be moved up the tree into its proper * place. */void UpdateModel( tree, c )TREE *tree;int c;{    int current_node;    int new_node;    if ( tree->nodes[ ROOT_NODE].weight == MAX_WEIGHT )        RebuildTree( tree );    current_node = tree->leaf[ c ];    while ( current_node != -1 ) {

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线播放高清精品| 亚洲一区中文在线| 国产日产欧美一区| 久久久99精品免费观看不卡| 欧美一激情一区二区三区| 欧美日韩国产另类一区| 欧美片网站yy| 日韩一级黄色大片| 久久一区二区视频| 欧美极品aⅴ影院| 成人欧美一区二区三区黑人麻豆| 成人免费在线观看入口| 亚洲激情在线激情| 亚洲国产精品视频| 免费看精品久久片| 国产一区二区0| 成人午夜av电影| 91免费观看国产| 欧美熟乱第一页| 日韩欧美三级在线| 国产亚洲一区字幕| 亚洲精品一二三| 日本成人在线看| 国产精品一区三区| 91在线观看一区二区| 欧美中文字幕久久| 欧美电影免费观看高清完整版在线观看| 日韩精品一区国产麻豆| 欧美韩国日本综合| 亚洲一本大道在线| 精一区二区三区| 成人免费的视频| 欧美亚洲免费在线一区| 日韩一卡二卡三卡四卡| 久久综合色婷婷| 亚洲视频中文字幕| 日韩高清电影一区| 风间由美一区二区三区在线观看 | 亚洲欧美日韩中文播放| 偷窥国产亚洲免费视频| 国产乱码一区二区三区| 91老师片黄在线观看| 91精品国产综合久久久久久久| 精品国产凹凸成av人网站| 国产精品白丝在线| 日韩黄色一级片| 成人免费看的视频| 91麻豆精品国产91久久久久久| 久久久影院官网| 亚洲在线视频网站| 国产成人免费在线| 欧美日韩黄视频| 国产精品三级在线观看| 日韩成人精品在线观看| 成人av午夜影院| 欧美一级生活片| 亚洲免费成人av| 国产高清不卡二三区| 欧美久久一区二区| 国产精品盗摄一区二区三区| 视频在线观看一区二区三区| 91在线高清观看| 国产亚洲综合色| 美女视频网站久久| 在线看不卡av| 日本一区二区三区国色天香 | 国产精品日韩精品欧美在线| 日本一区中文字幕| 日本精品视频一区二区| 国产日韩欧美制服另类| 久久精品国产一区二区| 欧美亚洲动漫精品| 亚洲欧美经典视频| 国产 欧美在线| 精品国产乱子伦一区| 亚洲一二三区在线观看| 91免费小视频| 国产精品久久久久久久蜜臀| 国产乱人伦偷精品视频免下载| 欧美一区永久视频免费观看| 一区二区三区在线观看网站| 波多野结衣中文一区| 日本一区二区三区免费乱视频| 麻豆精品一区二区三区| 5月丁香婷婷综合| 亚洲午夜三级在线| 在线亚洲人成电影网站色www| 国产精品乱人伦一区二区| 国产精品亚洲一区二区三区在线| 日韩精品中文字幕在线不卡尤物| 日韩精品一级二级 | 欧美人与性动xxxx| 夜夜精品视频一区二区| 91视频91自| 1000部国产精品成人观看| 国产夫妻精品视频| 久久久亚洲高清| 国产麻豆视频一区| 久久久精品国产免费观看同学| 久久黄色级2电影| 亚洲精品一区二区三区精华液 | 欧美一区二区三区婷婷月色| 肉丝袜脚交视频一区二区| 欧美性大战久久久久久久蜜臀| 亚洲久草在线视频| 91高清视频在线| 亚洲国产欧美另类丝袜| 欧美日韩国产系列| 日韩av一区二| 日韩精品一区二区三区蜜臀 | 一本色道久久加勒比精品| 亚洲色图欧美激情| 91成人看片片| 日韩二区三区四区| 日韩欧美专区在线| 国产精品一区在线观看乱码| 国产精品成人一区二区艾草 | 亚洲日本韩国一区| 欧美日韩卡一卡二| 日本美女一区二区三区视频| 精品国产乱码久久久久久久久 | 欧美一区二区三区视频免费 | 欧洲精品一区二区| 婷婷久久综合九色国产成人| 欧美videossexotv100| 国产精品自在欧美一区| 国产精品不卡在线观看| 欧美亚洲综合另类| 麻豆精品一区二区av白丝在线| 久久亚洲捆绑美女| 99国产精品久久久久久久久久久| 亚洲欧美经典视频| 欧美一区二区三区日韩| 岛国av在线一区| 亚洲精品一二三区| 日韩免费高清视频| 成人免费电影视频| 午夜精品久久久久久久99水蜜桃| 日韩免费一区二区| 99精品欧美一区二区三区小说| 亚洲成人自拍偷拍| 欧美不卡在线视频| av不卡免费在线观看| 亚洲国产视频一区二区| 久久久欧美精品sm网站| 色视频欧美一区二区三区| 蜜桃在线一区二区三区| 1024精品合集| 日韩精品一区二区在线| 99久久精品国产一区二区三区| 天天色综合天天| 亚洲国产高清在线观看视频| 欧美亚洲国产一区在线观看网站| 国内偷窥港台综合视频在线播放| 亚洲精品欧美在线| 久久日韩精品一区二区五区| 色狠狠色噜噜噜综合网| 国内精品久久久久影院薰衣草| 一区二区三区加勒比av| 久久久综合视频| 在线不卡中文字幕播放| 成人午夜av电影| 美女在线一区二区| 亚洲欧美一区二区三区极速播放 | 7777精品伊人久久久大香线蕉完整版| 国产激情一区二区三区| 天天色天天操综合| 中文字幕在线播放不卡一区| 精品久久久久久久久久久久包黑料| 91色乱码一区二区三区| 国产成人亚洲综合a∨猫咪| 亚洲高清视频的网址| 国产精品国产自产拍高清av王其| 欧美一级久久久久久久大片| 91成人国产精品| 成人动漫一区二区| 国产一区二区看久久| 天堂影院一区二区| 亚洲午夜激情网站| 日韩理论片在线| 国产精品丝袜一区| 久久精品综合网| 精品免费国产二区三区| 91精品国产美女浴室洗澡无遮挡| 色婷婷久久99综合精品jk白丝| 国产成人久久精品77777最新版本| 秋霞影院一区二区| 亚洲成人7777| 亚洲一区二区视频在线观看| 综合网在线视频| 国产精品网站一区| 国产丝袜欧美中文另类| 26uuu久久天堂性欧美| 欧美一区二区三区免费| 欧美高清性hdvideosex| 欧美日韩在线三区| 欧美日韩精品一区二区在线播放 | 中文一区二区在线观看| 久久久99精品免费观看| 欧美精品一区二|