Exemplo n.º 1
0
int main(int argc,char **argv)
{
	int ret;
	int i=0;
	int total[COUNT];
	int code_num = 0;
	huffman_tree root = NULL;
	HuffmanCode huffcode = NULL;
	memset(total,0,128*sizeof(int));
	if(0 != (ret = getTotalMs(compressFile,total)))
	{
		printf("ERROR:get Total Message Failed\n");
	}else if(0 != create_huffman_tree(root,total,COUNT))
	{
		printf("ERROR:create huffman tree Failed.\n");
	}else if(0 != huffman_encode(huffcode,root,COUNT,code_num))
	{
		printf("ERROR:Generate Code Failed\n");
	}else
	{
		//free(root);
		//free(huffcode);
	}
	printf("code Count :%d\n",code_num);
	for(i=0;i<code_num;i++)
	{
		printf("%d:%c      code is:",i,huffcode[i].character);
		printf("%s\n",huffcode[i].code);
	}
	system("pause");
	return 0;
}
Exemplo n.º 2
0
int32_t load_huffman_table(uint32_t *cpt, FILE *f, huff_table_t *ht)
{
       	printhead("%5u :      nb codes : ",*cpt);
	uint32_t init = *cpt;
	uint32_t tabnb[16];
	for (uint32_t i = 0; i < 16; i++) {
		uint8_t oct = read_byte(cpt,f);
		printhead("%x ",oct);
		tabnb[i] = oct;
	}
	printhead("\n%5u :      symboles : ┌─────────────────────────┐\n",*cpt);
	uint8_t **tabsym = create_huffman_table(tabnb,cpt,f);
	create_huffman_tree(tabnb,tabsym,ht);
	for (uint32_t i = 0; i < 16; i++) {
		free(tabsym[i]);
	}
	free(tabsym);
	return *cpt - init;
}
Exemplo n.º 3
0
void Word2Vec::build_vocab(vector<vector<string>> &sentences)
{
	unordered_map<string, int> word_cn;

	for(auto& sentence: sentences)
		for(auto& w: sentence)
			if(word_cn.count(w) > 0)
				word_cn[w]++;
			else
				word_cn[w] = 1;

	for(auto kv: word_cn)
	{
		if(kv.second < min_count)
			continue;

		Word *w = new Word(0, kv.second,  kv.first);
		vocab.push_back(w);
		vocab_hash[w->text] = WordP(w);
	}

	//update word index
	size_t vocab_size = vocab.size();
	sort(vocab.begin(), vocab.end(), comp);
	for(uint32_t i = 0; i < vocab_size; i++)
	{
		vocab[i]->index = i;
		idx2word.push_back(vocab[i]->text);
	}

	if(train_method == "hs")
		create_huffman_tree();

	if(negative)
		make_table();

	precalc_sampling();
}