コード例 #1
0
void test_LZ78_Compression_Variable_mode_given_input_file_sampleText_forCompresssion_2()
{
    InStream *in = initInStream();
    OutStream *out = initOutStream();
    Dictionary *dictionary = initDictionary(100);
    
    in = openInStream("test/support/Source/sampleText_forCompresssion_2.txt", "rb" , in);
    out = openOutStream("test/support/Compressed/Variable/sampleText_forCompresssion_Compressed_Variable_2.txt", "wb" , out);
      
    LZ78_Compressor(dictionary,in,out,Variable);
    
    TEST_ASSERT_EQUAL_STRING("A",dictionary->Entry[0].data);
    TEST_ASSERT_EQUAL_STRING("AA",dictionary->Entry[1].data);
    TEST_ASSERT_EQUAL_STRING("AAA",dictionary->Entry[2].data);
    TEST_ASSERT_EQUAL_STRING("AAA ",dictionary->Entry[3].data);
    TEST_ASSERT_EQUAL_STRING("B",dictionary->Entry[4].data);
    TEST_ASSERT_EQUAL_STRING("BB",dictionary->Entry[5].data);
    TEST_ASSERT_EQUAL_STRING("BBB",dictionary->Entry[6].data);
    TEST_ASSERT_EQUAL_STRING("BBBB",dictionary->Entry[7].data);
    TEST_ASSERT_EQUAL_STRING("C",dictionary->Entry[8].data);
    TEST_ASSERT_EQUAL_STRING("",dictionary->Entry[9].data);
    
    closeInStream(in);
    closeOutStream(out);
    freeInStream(in);
    freeOutStream(out);
    destroyDictionary(dictionary,100);
}
コード例 #2
0
//test case when dictionary is not full for decompression when index contain all zeroes only
void test_Decompression_given_1a1b1c_and_when_dictionary_is_not_full_should_decompress_correctly_into_abc()
{
    int value;
    OutStream out;
    Dictionary *dict = initDictionary(10);

    //create dictionary 
    value = AddDataToDictionary(dict, 1 , (unsigned int)('a')   );
    assert(value != 0);
    value = AddDataToDictionary(dict, 1 , (unsigned int)('b')   );
    assert(value != 0);
    value = AddDataToDictionary(dict, 1 , (unsigned int)('c')   );
    assert(value != 0);

    
    //create test fixture
    streamWriteBits_Expect(&out, (unsigned int)('a'), 8);           //expect a here
    streamWriteBits_Expect(&out, (unsigned int)('b'), 8);           //expect b here
    streamWriteBits_Expect(&out, (unsigned int)('c'), 8);           //expect c here
    
    //run
    Decompression(&out, 1 , (unsigned int)('a'), dict);
    Decompression(&out, 1 , (unsigned int)('b'), dict);
    Decompression(&out, 1 , (unsigned int)('c'), dict);
}
コード例 #3
0
/*test case when dictionary is not full, and merging of data occur
 *
 *  Given input = 1a2b
 */
void test_AddDataToDictionary_given_1a_2b_3c_and_size_is_larger_than_data_written_should_add_into_dictionary_correctly()
{
    int value;
    Dictionary *dict = initDictionary(10);
    
    value = AddDataToDictionary(dict, 1 , (unsigned int)('a')   );
    TEST_ASSERT_EQUAL(1, value);
    TEST_ASSERT_EQUAL(1, dict->currentIndex);
    TEST_ASSERT_EQUAL_STRING("a" ,dict->Entry[0].data);     TEST_ASSERT_EQUAL(1 ,dict->Entry[0].entrySize);
    TEST_ASSERT_EQUAL_STRING("" ,dict->Entry[1].data);     TEST_ASSERT_EQUAL(0 ,dict->Entry[1].entrySize);

   
    value = AddDataToDictionary(dict, 2 , (unsigned int)('b')   );
    TEST_ASSERT_EQUAL(1, value);
    TEST_ASSERT_EQUAL(2, dict->currentIndex);
    TEST_ASSERT_EQUAL_STRING("a" ,dict->Entry[0].data);     TEST_ASSERT_EQUAL(1 ,dict->Entry[0].entrySize);
    TEST_ASSERT_EQUAL_STRING("ab" ,dict->Entry[1].data);    TEST_ASSERT_EQUAL(2 ,dict->Entry[1].entrySize);
    
    value = AddDataToDictionary(dict, 3 , (unsigned int)('c')   );
    TEST_ASSERT_EQUAL(1, value);
    TEST_ASSERT_EQUAL(3, dict->currentIndex);
    TEST_ASSERT_EQUAL_STRING("a" ,dict->Entry[0].data);     TEST_ASSERT_EQUAL(1 ,dict->Entry[0].entrySize);
    TEST_ASSERT_EQUAL_STRING("ab" ,dict->Entry[1].data);    TEST_ASSERT_EQUAL(2 ,dict->Entry[1].entrySize);
    TEST_ASSERT_EQUAL_STRING("abc" ,dict->Entry[2].data);    TEST_ASSERT_EQUAL(3 ,dict->Entry[2].entrySize);
}
コード例 #4
0
ファイル: test.c プロジェクト: juhakivekas/TiRa_tyo
int test_initDictionary(){
	initDictionary(dict);
	int i;
	for(i=0; i<dict->wordCount; i++){
		if(dict->words[i]->S->data[0] != i){
			printf("FAIL:\tinitDictionary: values of initialized dictionary are wrong.\n");
			return 1;
		}
	}
	return 0;
}
コード例 #5
0
void test_getVariableIndex_given_4096_should_return_13()
{
    int numberofbits;
    
    //initialize dictionary
    Dictionary *dict = initDictionary(10);
    dict->currentIndex = 4095;
    
    numberofbits = getVariableIndex(dict);
    TEST_ASSERT_EQUAL(13 , numberofbits);
}
コード例 #6
0
void test_LZ78_Compression_Variable_mode_given_input_file_libjansson_4_dll_()
{
    InStream *in = initInStream();
    OutStream *out = initOutStream();
    Dictionary *dictionary = initDictionary(4096);
    
    in = openInStream("test/support/Source/libjansson-4.dll", "rb" , in);
    out = openOutStream("test/support/Compressed/Variable/libjansson-4_Compressed_Variable.dll", "wb" , out);
      
    LZ78_Compressor(dictionary,in,out,Variable);

    closeInStream(in);
    closeOutStream(out);
    freeInStream(in);
    freeOutStream(out);
    destroyDictionary(dictionary,4096);
}
コード例 #7
0
/*test case when dictionary is full, and try to add into dictionary
 *
 *  Given input = 1a2b
 */
void test_AddDataToDictionary_given_1a_2b_and_size_is_smaller_than_data_written_should_not_add_into_dictionary_correctly()
{
    int value;
    Dictionary *dict = initDictionary(1);
    
    value = AddDataToDictionary(dict, 1 , (unsigned int)('a')   );
    TEST_ASSERT_EQUAL(1, value);
    TEST_ASSERT_EQUAL(1, dict->currentIndex);
    TEST_ASSERT_EQUAL_STRING("a" ,dict->Entry[0].data);     TEST_ASSERT_EQUAL(1 ,dict->Entry[0].entrySize);

   
    value = AddDataToDictionary(dict, 2 , (unsigned int)('b')   );
    TEST_ASSERT_EQUAL(0, value);
    
    //Expect the whole dictionary stay the same as before
    TEST_ASSERT_EQUAL(1, dict->currentIndex);
    TEST_ASSERT_EQUAL_STRING("a" ,dict->Entry[0].data);     TEST_ASSERT_EQUAL(1 ,dict->Entry[0].entrySize);

}
コード例 #8
0
ファイル: LoadManager.cpp プロジェクト: uestcll/practice
void loadFile(FILE *fd,dictionary *& info)
{
	fgetc(fd);
	initDictionary(fd,info);
}
コード例 #9
0
ファイル: LZWcompress.c プロジェクト: juhakivekas/TiRa_tyo
int main(int argc, char* argv[]){

    if ( argc != 3 ) // argc should be 3 for correct execution
    {
        printf( "usage: %s input_filename output_filename\n", argv[0] );
    }

	//read text file into input array
	OriginalData* orig = readOriginalData(argv[1]);

	//allocate the same amount of compressed data (lets hope it is enough)
	CompressedData* compressed = newCompressedData(orig->dataLength, 8);

	//initializez the dictionary and the symbols in the dictionary
	Dictionary* dict = newDictionary(8);
	initDictionary(dict);

    printf("Compressing...\n");
	writeToCompressedData(compressed, dict->clearCode);

	MyString* S = newString();
	int codeword;
	int dictReturn;
	while(hasNextSymbol(orig)){
		appendString(S, (uint8_t) nextSymbol(orig));

		if(getCodeword(dict, S) != -1){
			;
		} else {
			//output S minus the last char 
			S->length--;
			codeword = getCodeword(dict, S);
			writeToCompressedData(compressed, codeword);
			S->length++;

			//great for debugging :
			// printf("wrote a %d bit codeword: %d\n", compressed->bitWidth, codeword);         
			// printf("Saved new word: %d    \t", dict->wordCount);
			// printString(S);
			// printf("\n");

			//add S to the dictionary
			dictReturn = addToDictionary(dict, S);

			if(dictReturn == -2){
				//for debugging :
            	// printf("--------------------------Increased Bit Width\n");

				//increase the bit width by one
				compressed->bitWidth++;
				dict->bitWidth *= 2;
			}
			if(dictReturn == -1){
				//dictionary is full, clear it and write a clearCode
				clearDictionary(dict);
				writeToCompressedData(compressed, dict->clearCode);
            	compressed->bitWidth = compressed->rootBitWidth+1;
				//step one symbol back in original data
				orig->nextSymbol--;
				orig->dataLeft++;
				//make S empty
				S->length = 0;
			}else{
				//"delete" the last character (it will still be in the data)
				S->length--;
				S->data[0] = S->data[S->length];//make S start with the "deleted" character
				S->length = 1;	//make the length of S 1, now S is the earlier last character
			}
		}
	}
	//write the last codeword
	codeword = getCodeword(dict, S);
	writeToCompressedData(compressed, codeword);

	//write EOI
	writeToCompressedData(compressed, dict->endOfInformation);

	writeCompressedDataToFile(compressed, argv[2]);  
    printf("File %s compressed succesfully to %s\n", argv[1], argv[2]);
    return 0;
}
コード例 #10
0
ファイル: crawler.c プロジェクト: aedalton16/tinysearchengine
int main(int argc, char* argv[])
{

  int current_depth; 
  int input_max_depth; 
  char* targetDir; 
  char seedURL[MAX_URL_LENGTH]; 
  char* page; 
  char* nextURLVisit;

  //char** URLList; 

  //check for proper command line arguments
  validateArgs(argc, argv);
  
  dict = initDictionary();
  
  current_depth = 0; 

  strcpy(seedURL, argv[1]);
  targetDir = argv[2]; 
  input_max_depth = atoi(argv[argc - 1]); 

  addElement(dict, seedURL, current_depth +1); 

  updateListLinkToBeVisited(dict, url_list, current_depth); 
  
  //installDNODE(seedURL, hash1(seedURL) % MAX_HASH_SLOT, 1); 
 
  page = getPage(seedURL, current_depth, targetDir); 
  if(page == NULL)
    {
      printf("Whoops, Cannot Crawl seed URL: %s ABORT ABORT! \n", seedURL);
      exit(1);

    }
  //URLsList......
  extractURLs(page, seedURL); 

  free(page); 
 
  updateListLinkToBeVisited(dict, url_list, current_depth + 1);

  //all the URLs parsed that dont exist, put in dict with DNODE and have thsi point to URLNODE 
  visited(dict, seedURL);
  
  //pointer to interger without a cast?
  while((nextURLVisit = getAddressFromLinksToBeVisited(dict, &current_depth)) !=NULL)
    {
      if (current_depth > input_max_depth)
	{
	  printf("[crawler]: URL %s exceeds specified depth of %d \n", nextURLVisit, input_max_depth); 
	  visited(dict, nextURLVisit);
	  continue; 
	}
      page = getPage(nextURLVisit, current_depth, targetDir); 
      if (page == NULL)
	{
	  printf("[crawler:] cannot Crawl URL: %s \n Marking as visited and trying again\n", nextURLVisit);
	  visited(dict, nextURLVisit);
	  continue; 
	}

      //need to malloc url list if going to update it, no?
      extractURLs(page, nextURLVisit);
      free(page); 

      //load into hash
      //if in url and not in dict add dnode 
      
      updateListLinkToBeVisited(dict, url_list, current_depth + 1); // this is where insert and install is called 
      visited(dict, nextURLVisit);

    }
  //free(url_list);
  //freeList(URLList); 
  printf("[crawler]: we out, time for cleans \n"); 
  cleanDict(dict);
  free(dict); 
  //dict = NULL; 
  //cleanList(dict);
  //  cleanDNodes(dict);
  printCrawlStats(); 
  return 0; 
}
コード例 #11
0
/************************************************************************************
 * READ ME FIRST before ANSWERING                                                   *
 *   1)  To facilitate the checking of the machine problem, follow the instructions *
 *       in each PROBLEM #.                                                         *
 *   2)  To accomplish the task for each PROBLEM, a series of function calls may be *
 *       necessary.                                                                 *  
 *   3)  Write you answer BELOW THE COMMENTS. DO NOT DELETE COMMENTS                *
 *   4)  Uncomment or copy the print statement in each PROBLEM#  if the task is     *
 *       completed.                                                                 *
 ***********************************************************************************/
 int main( ) 
 {	
 
    Dictionary A;
    dataList L;
    char *deleteID_01 = "12104029";
    char *deleteID_02 = "13101821"; 
    char *deleteID_03 = "13101820";
    char *lname_01 = "Baguio";
    char *lname_02 = "Ang";  
   
   
  
/*---------------------------------------------------------------------------------
 * 	Problem #1 ::  Display the ID, Complete name, and the Open and Closed Hash    *
 *                 values of each student record in one row.  Call function      *
 *                 displayHashValues().                                           * 
 *  printf("\n\n\nProblem #1:: ");                                                *
 *--------------------------------------------------------------------------------*/
	printf("\n\n\nProblem #1:: ");
     L = getData();
    displayHashValues(L);

	 
 
 
  
/*---------------------------------------------------------------------------------
 * 	Problem #2 ::  Displays an initially empty dictionary. It shows the  contents  *
 *                 of  both open and closed hash tables                           * 
 *                                                                                *
 *  printf("\n\n\nProblem #2:: ");                                                *
 *--------------------------------------------------------------------------------*/ 	 
 	printf("\n\n\nProblem #2:: ");
	initDictionary(&A);
 	displayOpenHashDic(A);
 
 
/*---------------------------------------------------------------------------------
 * 	Problem #3 ::  Populate and Display the dictionary by calling the             * 
 *                 displayDictionary().                  *
 *  printf("\n\n\nProblem #3:: ");                                                *
 *--------------------------------------------------------------------------------*/
 	printf("\n\n\nProblem #3::  ");
 	populateDictionary(A);
	displayDictionary(A);
 	

 
/*---------------------------------------------------------------------------------
 * 	Problem #4 ::  Call deleteManager 3 times passing deleteID_01, deleteID_02,   *
 *                 and deleteID_03.  Check if the records are deleted by calling  *
 *                 displayDictionary(A);                                          *
 *  printf("\n\n\nProblem #4:: ");                                                *
 *--------------------------------------------------------------------------------*/	
	printf("\n\n\nProblem #4:: ");

/*---------------------------------------------------------------------------------
 * 	Problem #5 ::  Call deleteUniqueManager 2 times passing lname_01 and lname_02. *
 *                 Check if the records are deleted by calling displayDictionary().*
 *  printf("\n\n\nProblem #5:: ");                                                 *
 *---------------------------------------------------------------------------------*/		     	
	printf("\n\n\nProblem #5:: ");
	getch();
	return 0;
}