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

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

?? 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 ) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久毛片高清国产| 国产a视频精品免费观看| 中文字幕av不卡| 久久综合久久综合九色| 日本不卡一二三| 亚洲女同ⅹxx女同tv| 高清不卡一区二区| 精品无人区卡一卡二卡三乱码免费卡 | 中文字幕视频一区| 国产亚洲欧美日韩日本| 国产精品区一区二区三| 亚洲色图欧洲色图| 亚洲一级电影视频| 日本最新不卡在线| 国内成人自拍视频| 成人综合激情网| 91视频.com| 欧美美女黄视频| 日韩精品最新网址| 久久久亚洲午夜电影| 国产精品久久久久久久久搜平片| 欧美国产亚洲另类动漫| 亚洲欧洲综合另类| 日韩成人伦理电影在线观看| 韩国在线一区二区| 波多野结衣视频一区| 在线视频国内自拍亚洲视频| 91精品午夜视频| 久久久久久电影| 亚洲欧美日韩国产成人精品影院| 日韩电影在线免费观看| 国产精品18久久久久| 99精品一区二区| 欧美日韩另类国产亚洲欧美一级| 日韩一级成人av| 亚洲精品老司机| 黄色精品一二区| 欧美三区免费完整视频在线观看| 精品少妇一区二区三区| 亚洲精品综合在线| 久久99精品国产麻豆不卡| 91污在线观看| 久久人人超碰精品| 亚洲午夜精品网| 99国产精品久久久| 精品1区2区在线观看| 亚洲成人激情自拍| 9i在线看片成人免费| 精品国产1区2区3区| 亚洲宅男天堂在线观看无病毒| 国产精品中文字幕日韩精品| 91久久精品一区二区| 国产视频一区不卡| 日本视频一区二区| 欧美三片在线视频观看 | 亚洲精品欧美二区三区中文字幕| 国产三级久久久| 老司机精品视频在线| 成人一区在线看| 日韩欧美国产午夜精品| 亚洲va欧美va人人爽午夜| 成人a免费在线看| 久久久综合激的五月天| 人人精品人人爱| 欧美高清精品3d| 无码av中文一区二区三区桃花岛| 色www精品视频在线观看| 国产精品嫩草99a| 高清不卡一区二区在线| 国产人伦精品一区二区| 国产精品中文字幕日韩精品| 久久中文字幕电影| 精品一区中文字幕| 欧美大片在线观看| 男女性色大片免费观看一区二区| 欧美日韩成人一区二区| 一区二区欧美国产| 在线精品视频免费播放| 亚洲午夜在线观看视频在线| 色欧美日韩亚洲| 亚洲综合999| 欧美日韩国产一区| 日本一区中文字幕| 日韩免费高清av| 国产乱人伦偷精品视频不卡| 久久久亚洲高清| a美女胸又www黄视频久久| 国产精品久久99| 色狠狠一区二区三区香蕉| 亚洲猫色日本管| 欧美性大战久久久久久久| 天天操天天干天天综合网| 欧美日韩精品是欧美日韩精品| 日韩av一区二区三区四区| 日韩一区二区电影网| 国产成人在线电影| 亚洲欧美一区二区在线观看| 欧美色精品天天在线观看视频| 青青青爽久久午夜综合久久午夜| 欧美成人精品二区三区99精品| 韩国成人在线视频| 国产精品久久久久影院| 欧美在线看片a免费观看| 麻豆精品视频在线| 中文字幕在线不卡| 欧美精品九九99久久| 国产成人午夜精品影院观看视频 | 国产成+人+日韩+欧美+亚洲| 国产精品福利一区二区三区| 色94色欧美sute亚洲线路二| 水蜜桃久久夜色精品一区的特点| 精品国产污污免费网站入口| 99久久婷婷国产综合精品| 亚洲va中文字幕| 国产欧美一区二区三区网站| 欧美中文字幕不卡| 国产精品亚洲成人| 日韩成人免费电影| 日韩一区在线免费观看| 欧美丰满美乳xxx高潮www| 国产成人一级电影| 日本特黄久久久高潮| 中文字幕一区二区在线播放| 777奇米四色成人影色区| 成人黄色综合网站| 麻豆高清免费国产一区| 一区二区三区四区五区视频在线观看 | 欧美va亚洲va香蕉在线| 99久久99久久综合| 国产精品一区在线观看乱码 | 欧美一区二区三区视频| 懂色一区二区三区免费观看| 日韩精品欧美精品| 一区二区三区在线看| 欧美激情综合五月色丁香| 91精品国产综合久久福利| 91国在线观看| 成人性视频网站| 国产高清不卡一区二区| 毛片av一区二区| 日本在线不卡视频| 午夜精品免费在线观看| 一区二区三区在线观看动漫| 国产精品每日更新| 亚洲国产成人在线| 久久综合色婷婷| 欧美sm美女调教| 日韩一级成人av| 日韩亚洲欧美一区| 欧美一区二区三区系列电影| 欧美三区在线观看| 在线播放视频一区| 欧美精品v日韩精品v韩国精品v| 欧美日韩一区成人| 欧美老年两性高潮| 欧美一二三区精品| 精品国产91乱码一区二区三区 | 国产成人av一区二区三区在线观看| 日韩激情av在线| 日本午夜精品视频在线观看| 奇米精品一区二区三区四区| 蜜臀久久99精品久久久画质超高清| 亚洲国产精品久久一线不卡| 亚洲成人在线网站| 七七婷婷婷婷精品国产| 激情深爱一区二区| 成人av在线播放网址| 成人avav影音| 欧美在线小视频| 日韩免费高清av| 久久久高清一区二区三区| 国产精品成人免费| 亚洲成人精品在线观看| 美美哒免费高清在线观看视频一区二区| 另类综合日韩欧美亚洲| 懂色中文一区二区在线播放| 欧美专区在线观看一区| 91精品国产色综合久久不卡电影 | 一区二区三区中文在线观看| 国产精品污www在线观看| 国产成人精品免费视频网站| 久久99精品久久久久| 国产精品18久久久久| 91香蕉视频黄| 欧美一区二区三区白人| 久久精品日产第一区二区三区高清版 | 色999日韩国产欧美一区二区| 91精品国产综合久久精品| 国产午夜精品一区二区三区嫩草 | 亚洲国产毛片aaaaa无费看| 亚洲成av人影院在线观看网| 狠狠色丁香婷婷综合久久片| 福利一区二区在线| 欧美高清视频www夜色资源网| 2024国产精品| 亚洲国产成人精品视频| 国产精品1区2区3区| 国产不卡在线播放| 日韩精品午夜视频| 蜜桃一区二区三区在线|