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

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

?? huffman-compress.c

?? 自適應哈弗曼(adaptive huffman)壓縮和解壓程序
?? C
字號:
/*
 * File:      huffman-compress.c
 * Author:    JD, with a bit of code pirated from a 2103 student
 * Date:      2008-02-03
 * Version:   1.1
 *
 * Description:   This program reads in either stdin or the given file
 *	argument and compresses this data using Huffman compression.  The
 *	output is written to stdout (if the input was stdin) and is
 *	otherwise written to the same file name as the original with ".huf"
 *	appended.
 *
 *	If the first argument is "-a", the output codes (but not the
 *	overhead data) are written in ASCII, one code per line.
 */


#include    <stdio.h>
#include    <stdlib.h>
#include    <stdint.h>	    /* C99 */
#include    <ctype.h>
#include    <string.h>


#define	    NUM_SYMBOLS	    256
#define	    NUM_ITEMS       (2 * NUM_SYMBOLS - 1)
#define	    MAX_NUM_MERGES  (NUM_SYMBOLS - 1)
#define	    NO_MORE         (-1)
#define     NO_PARENT	    (-1)


typedef struct
{
    uint32_t count;
    short parent_index;
    short code_length;
    char code[MAX_NUM_MERGES];
    char merged;
    char left_or_right;		    /* left or right child of parent? */
} Item_t;


int get_smallest(Item_t items[], int length);
void write_bit(int bit);
void flush_bits();
int parse_args(int argc, char * argv[], int * ascii_output);
void write_header(Item_t items[], int ascii_output);



void
usage(const char * progname)
{
    fprintf(stderr, "Usage: %s [-a] [infile]\n", progname);
}



int
main(int argc, char * argv[])
{
    int input, i, j, next_item;
    int small1, small2;
    Item_t items[NUM_ITEMS];
    int ascii_output = 0;

    if (parse_args(argc, argv, &ascii_output) != 0)
	return EXIT_FAILURE;

    for (i = 0; i < NUM_ITEMS; i++)
    {
	items[i].count = 0;
	items[i].merged = 0;
	items[i].parent_index = NO_PARENT;      
    }

    /* Read the input */
    while ((input = getchar()) != EOF)
	items[input].count++;

    write_header(items, ascii_output);

    /* Merge the items */
    next_item = NUM_SYMBOLS;
    while (1)
    {
	small1 = get_smallest(items, NUM_ITEMS);
	if (small1 == NO_MORE)
	    break;
	items[small1].merged = 1;

	small2 = get_smallest(items, NUM_ITEMS);
	if (small2 == NO_MORE)
	    break;
	items[small2].merged = 1;

	items[small1].left_or_right = 0;
	items[small1].parent_index = next_item;

	items[small2].left_or_right = 1;
	items[small2].parent_index = next_item;

	items[next_item].count = items[small1].count + items[small2].count;
	next_item++;
    }

    /* Compute the codes */
    for (i = 0; i < NUM_SYMBOLS; i++)
    {
	char rev_code[MAX_NUM_MERGES];
	int item_index;

	if (items[i].count == 0)
	    continue;

	for (j = 0, item_index = i;
	     items[item_index].parent_index != NO_PARENT; j++)
	{
	    rev_code[j] = items[item_index].left_or_right;
	    item_index = items[item_index].parent_index;
	}

	items[i].code_length = 0;
	j--;
	while (j >= 0)
	    items[i].code[items[i].code_length++] = rev_code[j--];

#ifdef DEBUG
	fprintf(stderr, "Code for char %d is", i);
	for (j = 0; j < items[i].code_length; j++)
	    fprintf(stderr, " %d", items[i].code[j]);
	fprintf(stderr, "\n");
#endif
    }

    /* Output codes for each letter */
    rewind(stdin);
    if (ascii_output)
	while ((input = getchar()) != EOF)
	{
	    for (i = 0; i < items[input].code_length; i++)
		printf("%d", items[input].code[i]);
	    printf("\n");
	}
    else
    {
	while ((input = getchar()) != EOF)
	    for (i = 0; i < items[input].code_length; i++)
		write_bit(items[input].code[i]);
	flush_bits();
    }

    return EXIT_SUCCESS;
}



/*
 * Function:  parse_args
 * Purpose:   Examine the arguments and freopen() streams as necessary.
 * Inputs:    argc, argv and a pointer to an int
 * Returns:   0 on success, non-zero on failure
 *
 * Error checking: enough...
 * Sample usage: parse_args(argc, argv, &use_ascii_output);
 */

int
parse_args(int argc, char * argv[], int * ascii_output)
{
    char * progname = argv[0];

    if (argc > 1 && 0 == strcmp(argv[1], "-a"))
    {
	*ascii_output = 1;
	argc--;
	argv++;
    }
    if (argc > 2)
    {
	usage(argv[0]);
	return 1;
    }
    if (argc > 1)
    {
	char * outfile;

	if (freopen(argv[1], "r", stdin) == NULL)
	{
	    fprintf(stderr, "%s: unable to open input file '%s' for reading\n",
		    progname, argv[1]);
	    return 2;
	}
	outfile = malloc(strlen(argv[1] + 5));
	if (outfile == NULL)
	{
	    fprintf(stderr, "%s: unable to allocate memory; quitting\n",
		    progname);
	    return 3;
	}
	strcpy(outfile, argv[1]);
	strcat(outfile, ".huf");
	if (freopen(outfile, "w", stdout) == NULL)
	{
	    fprintf(stderr, "%s: unable to open output file '%s' for writing\n",
		    progname, outfile);
	    return 4;
	}
    }

    return 0;
}



/*
 * Function:  write_header
 * Purpose:   Write out the header, which precedes all the codes.
 * Inputs:    items[] and ascii_output
 * Returns:   nothing
 *
 * Error checking: none
 * Sample usage: write_header(items, ascii_output);
 *
 * The header starts with two ints which specify the min and max symbol
 * values.  Then it follows this with a 'b', 'h' or 'w' according to
 * whether the counts are output with unsigned bytes, halfwords or words.
 * Then the counts themselves are output in binary.
 */

void
write_header(Item_t items[], int ascii_output)
{
    int i, min_symb, max_symb, max_count;

    i = 0;
    for (i = 0; items[i].count == 0 && i < NUM_SYMBOLS; i++)
	;
    min_symb = i;
    max_symb = i;
    max_count = items[i].count;
    for (i++; i < NUM_SYMBOLS; i++)
    {
	if (items[i].count > 0)
	{
	    if (items[i].count > max_count)
		max_count = items[i].count;
	    max_symb = i;
	}
    }

    fwrite(&min_symb, sizeof(min_symb), 1, stdout);
    fwrite(&max_symb, sizeof(max_symb), 1, stdout);
    if (max_count < 256)
    {
	unsigned char byte;

	fputc((unsigned)'b', stdout);
	for (i = min_symb; i <= max_symb; i++)
	{
	    byte = items[i].count;
	    fwrite(&byte, sizeof(byte), 1, stdout);
	}
    }
    else if (max_count < 65536)
    {
	uint16_t halfword;

	fputc((unsigned)'h', stdout);
	for (i = min_symb; i <= max_symb; i++)
	{
	    halfword = items[i].count;
	    fwrite(&halfword, sizeof(halfword), 1, stdout);
	}
    }
    else
    {
	uint32_t word;

	fputc((unsigned)'w', stdout);
	for (i = min_symb; i <= max_symb; i++)
	{
	    word = items[i].count;
	    fwrite(&word, sizeof(word), 1, stdout);
	}
    }

    if (ascii_output)
	printf("\n");
}



/*
 * Function:  get_smallest
 * Purpose:   Gets the un-merged item with the smallest count.
 * Inputs:    items[] and length
 * Returns:   an int >= 0 or NO_MORE (NO_MORE if all items are merged)
 *
 * Error checking: none
 * Sample usage: get_smallest(items, MAX);
 */

int
get_smallest(Item_t items[], int length)
{
    int smallest = NO_MORE;      /* Smallest item index */
    int i;

    for (i = 0; i < length; i++)
    {
	if (items[i].merged || items[i].count == 0)
	    continue;

	if (smallest == NO_MORE)
	    smallest = i;
	else if (items[i].count < items[smallest].count)
	    smallest = i;
    }

    return smallest;
}



/*
 * Declare two global variables here, so they can only be used by the
 * functions below here.
 *
 * Note for 2103 students:
 * These two functions need to share the two variables.  We could pass
 * these as parameters to the functions, or combine the two functions into
 * one so that the global variables would be static inside the function.
 * To make that latter way work, we would need another parameter to the
 * write_bit() function to tell it to flush the last few bits, and I like
 * that design less than the way I did it.
 */

static unsigned char byte = 0;
static int bits_used = 0;


void
write_bit(int bit)
{
    byte <<= 1;
    byte |= bit;
    if (++bits_used == 8)
    {
	fwrite(&byte, sizeof(byte), 1, stdout);
	byte = 0;
	bits_used = 0;	
    }
}


void
flush_bits()
{
    if (bits_used > 0)
    {
	byte <<= 8 - bits_used;
	fwrite(&byte, sizeof(byte), 1, stdout);
	byte = 0;
	bits_used = 0;	
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区免费在线观看| www.在线成人| 成人福利电影精品一区二区在线观看| 色综合久久久网| 久久久久亚洲蜜桃| 亚洲va天堂va国产va久| 成人午夜大片免费观看| 日韩精品资源二区在线| 亚洲午夜免费视频| 成人91在线观看| 欧美激情一区二区在线| 国产在线精品视频| 日韩一区二区三区电影在线观看| 亚洲欧美区自拍先锋| 国产ts人妖一区二区| 337p日本欧洲亚洲大胆精品| 午夜精品久久久久久久久久 | 一本到不卡精品视频在线观看| 日韩精品一区二区三区swag | 欧美图片一区二区三区| 国产精品视频你懂的| 国产福利91精品一区二区三区| 日韩欧美在线影院| 蜜臀av性久久久久av蜜臀妖精| 欧美日韩三级在线| 亚洲国产精品尤物yw在线观看| 色狠狠一区二区三区香蕉| 亚洲人成网站色在线观看| 色哟哟国产精品免费观看| 亚洲人成网站精品片在线观看| 91蜜桃网址入口| 亚洲女同一区二区| 欧美日韩视频专区在线播放| 一区二区三区不卡视频| 欧美色中文字幕| 亚洲高清免费观看高清完整版在线观看 | 成人小视频免费在线观看| 国产色产综合产在线视频| 国产精品18久久久久久久网站| 久久夜色精品国产噜噜av| 国产在线精品国自产拍免费| 久久精品欧美一区二区三区麻豆| 国产一区二区三区在线观看精品 | 亚洲成人777| 欧美精品久久天天躁| 首页国产欧美久久| 欧美刺激脚交jootjob| 国产在线看一区| 中文字幕一区二区三中文字幕| 99re这里只有精品视频首页| 亚洲综合激情另类小说区| 欧美疯狂做受xxxx富婆| 久久精品国产第一区二区三区| 欧美大片一区二区| 成人黄色综合网站| 亚洲国产aⅴ天堂久久| 精品欧美久久久| 95精品视频在线| 日韩中文字幕av电影| 久久久久亚洲综合| 欧美中文一区二区三区| 狠狠色丁香九九婷婷综合五月| 国产精品福利一区| 色噜噜狠狠成人中文综合| 久久国产尿小便嘘嘘尿| 亚洲欧美成aⅴ人在线观看| 337p亚洲精品色噜噜| 国产乱人伦偷精品视频不卡| 亚洲色图视频网站| 欧美高清一级片在线| 国产v日产∨综合v精品视频| 午夜视频一区在线观看| 中文字幕巨乱亚洲| 4438x成人网最大色成网站| 99国产一区二区三精品乱码| 日韩高清欧美激情| 亚洲私人黄色宅男| 久久亚洲综合av| 欧美精品日日鲁夜夜添| 成人av网站在线观看免费| 日韩**一区毛片| 亚洲精选在线视频| 国产人久久人人人人爽| 7777精品久久久大香线蕉| 不卡欧美aaaaa| 国产一区二区三区高清播放| 视频一区二区三区入口| 国产精品久久久久久久久动漫| 日韩欧美亚洲另类制服综合在线| 99国产精品国产精品毛片| 国产激情一区二区三区四区| 免费的国产精品| 一区二区不卡在线视频 午夜欧美不卡在| 91精品婷婷国产综合久久| 91黄色免费版| 99久久综合国产精品| 国产精品一区二区久久不卡| 免费成人在线视频观看| 日韩精品每日更新| 亚洲免费毛片网站| 亚洲欧洲av另类| 欧美激情一区二区三区四区| 久久久久久久久免费| 日韩欧美在线综合网| 欧美一区二区视频在线观看2022 | 丝袜美腿亚洲色图| 无码av免费一区二区三区试看| 曰韩精品一区二区| ...中文天堂在线一区| 国产精品高潮呻吟久久| 国产精品福利在线播放| 一区在线观看免费| 中文字幕一区二区三区不卡| 中文字幕一区三区| 亚洲品质自拍视频网站| 亚洲欧美日韩在线| 亚洲夂夂婷婷色拍ww47| 香蕉乱码成人久久天堂爱免费| 亚洲第一成人在线| 丝袜美腿成人在线| 久久国产精品72免费观看| 经典一区二区三区| 国产精品99久久久久久宅男| 岛国av在线一区| 色综合天天视频在线观看| 日本韩国精品在线| 4hu四虎永久在线影院成人| 日韩午夜激情免费电影| 久久这里只有精品6| 国产精品久久99| 亚洲一区二区不卡免费| 日本美女视频一区二区| 国产毛片精品视频| www.欧美精品一二区| 色老汉av一区二区三区| 欧美一级生活片| 久久人人超碰精品| 亚洲丝袜另类动漫二区| 水蜜桃久久夜色精品一区的特点 | 在线免费不卡视频| 欧美高清性hdvideosex| 国产午夜亚洲精品羞羞网站| 亚洲欧美综合另类在线卡通| 三级成人在线视频| 国产伦精品一区二区三区免费迷| 成人黄色在线视频| 91精品福利在线一区二区三区| 久久久久久麻豆| 亚洲高清免费在线| 国产成人aaa| 欧美妇女性影城| 国产女同互慰高潮91漫画| 亚洲天天做日日做天天谢日日欢 | 国产精品白丝jk黑袜喷水| 91麻豆精品在线观看| 日韩一级免费观看| 久久美女高清视频| 亚洲无人区一区| 国产成人免费高清| 欧美丰满高潮xxxx喷水动漫| 国产人久久人人人人爽| 视频一区欧美日韩| av动漫一区二区| 久久综合色婷婷| 天涯成人国产亚洲精品一区av| 成人免费福利片| 日韩美女天天操| 亚洲国产视频在线| 99在线精品免费| 国产免费成人在线视频| 麻豆国产精品一区二区三区 | 欧美性色aⅴ视频一区日韩精品| 2019国产精品| 热久久一区二区| 精品视频一区二区不卡| 综合自拍亚洲综合图不卡区| 国产九色sp调教91| 欧美电影免费观看高清完整版在| 一区二区成人在线视频| 99这里只有久久精品视频| 久久日一线二线三线suv| 性做久久久久久久久| 在线免费不卡视频| 亚洲欧美激情一区二区| 99久久综合国产精品| 国产日韩欧美一区二区三区综合| 蜜臀av一区二区三区| 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 国产午夜精品一区二区三区四区| 蜜臀av在线播放一区二区三区| 欧美精品乱码久久久久久| 香港成人在线视频| 欧美日韩亚洲另类| 亚洲资源中文字幕| 欧美无砖砖区免费| 视频一区国产视频| 日韩亚洲欧美成人一区| 日本特黄久久久高潮| 日韩无一区二区| 国内成人自拍视频|