Beispiel #1
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input2.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    FILE *ifp;
    char *mode = "r";
    char *word, key;
    ifp = fopen(filename, mode);
    assert(ifp);
    while((word = getWord(ifp)) != NULL){
            if(word)
                insertMap(hashTable, word, 1);
    }
    fclose(ifp);
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

    printf("Deleting keys\n");

	removeKey(hashTable, "bitter");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
//	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
Beispiel #2
0
int main(int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 63;
	clock_t timer;
	FILE *fileptr;
	/*
	this part is using command line arguments, you can use them if you wish
	but it is not required. DO NOT remove this code though, we will use it for
	testing your program.

	if you wish not to use command line arguments manually type in your
	filename and path in the else case.
	*/
	if (argc == 2)
		filename = argv[1];
	else
		filename = "input1.txt"; /*specify your input text file here*/

	printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

	/*... concordance code goes here ...*/
	fileptr = fopen(filename, "r"); //open the given file

	if (fileptr != NULL) //if the file was opened sucessfully...
	{
		/* while the end of the file has not yet been reached, get the next word in the file, 
		 * adding it to the hash table or updating the number of times it has appeared in the document.
		 * the alogrithm is case sensitive
		 */
		while (!feof(fileptr)) 
		{
			char* word = getWord(fileptr);

			if (word != NULL)
			{
				int* wordCount = atMap(hashTable, word);

				if (wordCount == NULL)
				{
					insertMap(hashTable, word, 1);
				}
				else
				{
					insertMap(hashTable, word, (*wordCount) + 1);
				}
			}
		}
	}
	else
	{
		fprintf(stderr, "Could not open file."); //print an error message if the file could not be opened
	}

	fclose(fileptr); //close the file

	//print each word in the document along with the number of times it has appeared. 
	for (int i = 0; i < hashTable->tableSize; i++)
	{
		hashLink* curLink = hashTable->table[i];

		while (curLink != NULL)
		{
			printf("%s: %d\n", curLink->key, curLink->value);

			curLink = curLink->next;
		}
	}
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
	printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
Beispiel #3
0
int main (int argc, const char * argv[]) {
    const char* filename;
    struct hashMap *hashTable;
    int tableSize = 10;
    clock_t timer;
    FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc >= 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

    fileptr = fopen(filename, "r");
    if(fileptr == NULL) {
        char err[255];
        sprintf(err, "Failure opening file %s; exiting.\n", filename);
        perror(err);
        exit(EXIT_FAILURE);
    }

    timer = clock();

    hashTable = createMap(tableSize);

    char *curr;
    ValueType *val;

    while((curr = getWord(fileptr)) != NULL) {
        if((val = atMap(hashTable, curr)) != NULL)
            (*val)++;
            //insertMap(hashTable, curr, (*val)+1);
        else
            insertMap(hashTable, curr, 1);
        free(curr);
    }

    fclose(fileptr);
    //fclose(outfileptr);

    printMap(hashTable);
    timer = clock() - timer;
    printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));

    printf("Deleting keys\n");

    removeKey(hashTable, "and");
    removeKey(hashTable, "me");
    removeKey(hashTable, "the");
    //printMap(hashTable);

    deleteMap(hashTable);
    printf("\nDeleted the table\n");
    return 0;
}
Beispiel #4
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    fileptr = fopen(filename, "r");
    if (fileptr != NULL) {
        int *val, *x;
        char *word;
        while ((word = getWord(fileptr))) {
            if (containsKey(hashTable, word)) {
                val = (int *) atMap(hashTable, word);
                (*val) ++;
                free(word);
            } else {
                x = malloc(sizeof(int));
                *x = 1;
                insertMap(hashTable, word, x);
            }
        }
        fclose(fileptr);
    } else printf("Error opening file.\n");
	/*... concordance code ends here ...*/

	printMap(hashTable, keyPrint, valPrint);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
    printMap(hashTable, keyPrint, valPrint);
    printKeyValues(hashTable, keyPrint, valPrint);
         /* Test out the iterator */
#ifdef ITERATOR_IN
         struct mapItr *myItr;
         myItr = createMapIterator(hashTable);

         KeyType  key;

         /* Free up our keys and values using our iterator!!  Also printing them as we go along */
         while(hasNextMap(myItr))
           {
             key = nextMap(myItr);
             int *value = atMap(hashTable,key);
             printf("Freeing ...Key = %s, value = %d \n", key, *value);
             free(value);  /* To match the malloc above*/
             free(key);

           }
#endif


        deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
Beispiel #5
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	char *word;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
	int *numWordOccurances;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    	printf("opening file: %s\n", filename);

	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
	// generate concordance
	fileptr = fopen(filename,"r");	
	while (!feof(fileptr)) {	

		word = getWord(fileptr);

		if(!word){
			break;
		}
		numWordOccurances = (int *)atMap(hashTable, word); /* cast return of atMap to int*/
		
		if(numWordOccurances!=0){			
			(*numWordOccurances)++;
		} else {
			/* need to malloc numWordOccurances before insertMap*/
			numWordOccurances = (int *) malloc(sizeof(int));
			*numWordOccurances = 1;
			insertMap(hashTable, word, numWordOccurances);		
		}
	}	

	// print concordance
	printMap(hashTable);
	
	// print hashmap statistices
	fclose(fileptr);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys: \"and\", \"me\", and \"the\"\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #6
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;

    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    FILE *file;
    file = fopen(filename, "r");
    /* if there is no file named that */
    if(!file){
        printf("Unable to open file. \n");
    }
    /* loops until the end of the file */
    while(!feof(file)){
        char *word = getWord(file);
        if(word){
            if(containsKey(hashTable, word)){
                int *value = atMap(hashTable, word);
                ++(*value);
            }
            else{
            insertMap(hashTable, word, 1);
            }
        }
    }


	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
Beispiel #7
0
int main (int argc, const char * argv[]) {
    const char* filename;
    struct hashMap *hashTable;
    int tableSize = 10;
    clock_t timer;
    FILE *fileptr;
    /*
     Optional command line argument usage for filename
    if(argc == 2)
    //    filename = argv[1];
    //else*/
    filename = "input2.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

    timer = clock(); /*Used to calculate efficiency*/
    hashTable = createMap(tableSize);	   /*Create a new hashMap*/
    fileptr = fopen(filename, "r");/*Open the file*/
    assert(fileptr != NULL);/*Check that the file opened properly*/
    int * value;/*Used to receive the value at the key*/


    for (char* word = getWord(fileptr); word != NULL; word = getWord(fileptr)) /*While the file hasn't reached the end*/
    {
        if (containsKey(hashTable, word) == 1) {
            /*If the key is already in the hash table, get the current value at that key and increment it by 1.
            Then reinsert that key with the new value*/
            value = atMap(hashTable, word);
            *value+=1;
            insertMap(hashTable, word, *value);
        }

        else
            insertMap(hashTable, word, 1); /*else insert the key with a value of 1*/
    }


    fclose(fileptr);/*close the file*/

    printMap(hashTable);/*Print the keys and values in the hashMap*/


    timer = clock() - timer;
    /*Print statements for testing purposes*/
    printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));


    /*Test the removeKey function*/
    printf("Deleting keys\n");
    removeKey(hashTable, "and");
    removeKey(hashTable, "me");
    removeKey(hashTable, "the");

    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));
    printMap(hashTable);

    /*Delete the hashMap*/
    deleteMap(hashTable);
    printf("\nDeleted the table\n");
    return 0;
}
Beispiel #8
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 1000;
	clock_t timer;
	FILE *fileptr;	
 	   /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	/*... concordance code goes here ...*/

       	hashTable = createMap(tableSize); 
       
	fileptr = fopen(filename, "r");
//	char *character = "";

	 
//	ValueType* val; 
//	val = atMap(hashTable, character); 
/*
 * I couldnt figure out how to properly set up the concordance*/
		
		insertMap(hashTable, getWord(fileptr), 0); 
		insertMap(hashTable, getWord(fileptr), 0);
		insertMap(hashTable, getWord(fileptr), 0); 
		insertMap(hashTable, getWord(fileptr), 0); 

	
	fclose(fileptr);   		
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
   	printf("Table count = %d\n", size(hashTable));


printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #9
0
int main (int argc, const char * argv[]) {
	char *fn; /* File name */
	struct hashMap *hashTable, *hashTable2;
	FILE *filePtr;

	fn = "text1.txt";/* the file name and path */
	printf("Opening file: %s \n", fn);
	filePtr = fopen(fn, "r");
	hashTable = createMap(40, 1);
  char *word;
  while((word = getWord(filePtr)) != '\0') {
      insertMap(hashTable, word, 1);
  }

  printf("--------------- Testing contains --------------- \n");

  assertTrue(containsKey(hashTable, "it") == 1, "Search for 'it'");
  assertTrue(containsKey(hashTable, "comparison") == 1, "Search for 'comparison'");
  assertTrue(containsKey(hashTable, "period") == 1, "Search for 'period'");
  assertTrue(containsKey(hashTable, "despair") == 1, "Search for 'despair'");
    assertTrue(containsKey(hashTable, "deriop") == 0, "Search for 'deriop'");
    assertTrue(containsKey(hashTable, "yuck") == 0, "Search for 'yuck'");

    printf("--------------- Testing table stats --------------- \n");

    assertTrue(hashTable->tableSize == 40, "Test table size");
    assertTrue(fullBuckets(hashTable) == 30, "Test full buckets");
    assertTrue(emptyBuckets(hashTable) == 10, "Test empty buckets");
    assertTrue(linkCount(hashTable) == 59, "Test link count");

    printf("--------------- Testing remove --------------- \n");

    removeKey(hashTable, "yuck"); /* Should print some type of 'not found' message */
    removeKey(hashTable, "despair");
    assertTrue(containsKey(hashTable, "despair") == 0, "Search for 'despair'");

    printf("--------------- Printing hash table --------------- \n");

    printMap(hashTable);

    deleteMap(hashTable);

    printf("--------------- New table - same text file - new hash --------------- \n");

    fn = "text1.txt";/* the file name and path */
		printf("Opening file: %s \n", fn);
		filePtr = fopen(fn, "r");
		hashTable2 = createMap(40, 2);

    while((word = getWord(filePtr)) != '\0') {
        insertMap(hashTable2, word, 1);
    }

    printf("--------------- Testing table stats 2 --------------- \n");

    assertTrue(hashTable2->tableSize == 80, "Test table size");
    assertTrue(fullBuckets(hashTable2) == 38, "Test full buckets");
    assertTrue(emptyBuckets(hashTable2) == 42, "Test empty buckets");
    assertTrue(linkCount(hashTable2) == 59, "Test link count");

    printf("Closing file: %s \n", fn);
		fclose(filePtr);

	/* Concordance testing	*/




	struct hashMap * concord;

  fn = "text2.txt";
	printf("Opening file: %s \n", fn);
	filePtr = fopen(fn, "r");
	concord = createMap(10, 2);


    while((word = getWord(filePtr)) != '\0') {
        concordance(concord, word);
    }

    printf("--------------- Concordance table stats --------------- \n");

    printf("table size: %d \n", concord->tableSize);
    printf("full buckets: %d \n", fullBuckets(concord));
    printf("empty buckets: %d \n", emptyBuckets(concord));
    printf("link count: %d \n", linkCount(concord));



    /*Test further on your own */

	return 0;
}
Beispiel #10
0
int main (int argc, const char * argv[]) {
	char *word;
	ValueType *value;
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
	/*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");
	
	
	while(1){
		
		word = getWord(fileptr);
		if(word == NULL){
			break;
		}		
		value = atMap(hashTable, word);
		if(value == NULL)
		{
			value = malloc(sizeof(int*));
			*((int*)value) = 1;
		}
		else if(value != NULL)
		{
			*((int *)value) += 1;
		}
		insertMap(hashTable, word, ((void *)value));
	
	}
   
			
	/*... concordance code ends here ...*/
	

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);


		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #11
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");

	if (!fileptr)
	{
	   printf("Error Opening File.\n");
	}

	char *word = getWord(fileptr);
	//ValueType val;
	
	while (word != 0)
	{
	   //char *word = getWord(fileptr);
	   // Check table for word, insert if not found
	   if (containsKey(hashTable, word)== 0)
	   {
	      insertMap(hashTable, word, 1);
	   }
	   else
	   {
	       (*atMap(hashTable, word))++;
	   }
	   word = 0;
	   free(word);
	   word = getWord(fileptr);
	}

	fclose(fileptr);
	
	printf("\n");
	hashLink * temp;

	for (int i = 0; i < hashTable->tableSize; i++)
	{
	   temp = hashTable->table[i];
	   while (temp != 0)
	   {
	      printf("%s: %d\n", temp->key, temp->value);
	      temp = temp->next;
	   }
	}
	free(temp);	
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #12
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");
	char* word;
	char words[95][16];   // store words here to print later
	
  
	int count = 0;  

	// loop over words in filename adding them to the map
	while (( word = getWord(fileptr)))
	  {
	    //words[count] = malloc(strlen(word));
	    strcpy(words[count],word);
	    count++;
	    
	    if (containsKey(hashTable, word))
	      {
		ValueType *val = atMap(hashTable, word);
		(*val)++;
		free(word);
	      }
	    else
	      {
		insertMap(hashTable, word, 1);
	      }
	    
	  }
	fclose(fileptr);

	// loop over words
	printf("word count: %d\n",count);
	printf("table size: %d\n",hashTable->tableSize);

	for (int i=0; i < count; i++)
	  {
	    //int v = val;
	    word = words[i];
	    //printf("%d: ",i);
	    printf("%s: ",word);
	    printf("%d \n",(*atMap(hashTable,word)));
	  }
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
	printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #13
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 97;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input2.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/

	fileptr = fopen(filename, "r");
	char* word = getWord(fileptr);

	do
	{
		//if the word is in the hashTable, increment the val
		//otherwise, create the entry with value set to 1
		if (containsKey(hashTable, word))
		{
			//atMap is useless?
			int *val = atMap(hashTable, word);
			*val += 1;
			int i = 0;
		}
		else
		{
			int val = 1;
			insertMap(hashTable, word, val);
		}

		word = getWord(fileptr);
	} while (word != NULL);

	fclose(fileptr);

	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #14
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
	
	/*open file*/
	fileptr = fopen(filename, "r");

	/*read words from file*/
	char* word;
	while((word = getWord(fileptr))){
		//make word lowercase
		/*if the occurance is already in the ht, val++*/
		if(containsKey(hashTable, word)){	
			ValueType* value = atMap(hashTable, word);
			*value += 1;
			insertMap(hashTable, word, *value);
		}
		/*else, add it*/
		else{
			insertMap(hashTable, word, 1);
		}
	}
	free(word);
	/*close file*/
	fclose(fileptr);

	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
Beispiel #15
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
  int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
  void*  key;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
  if(argc == 2)
      filename = argv[1];
  else
      filename = "input1.txt"; /*specify your input text file here*/

  printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);
  printf("Successfully created hashtable\n");
	/*... concordance code goes here ...*/
    fileptr = fopen(filename, "r+");
    char* wordNext = "starter";
    while(wordNext != 0) {
        wordNext = getWord(fileptr);
        if(wordNext != 0) {
            if(containsKey(hashTable, wordNext, myCompare, hash2) == 0){
                void* v = malloc(sizeof(void*));
                *(int*)v = 1;
                insertMap(hashTable, wordNext, v, myCompare, hash2);
            }
            else {
                /*int newVal = *(int*)(atMap(hashTable, wordNext, myCompare, hash2)) + 1;
                 void* newVal2 = &newVal;
                 insertMap(hashTable, wordNext, newVal2, myCompare, hash2);*/
                *(int*)(atMap(hashTable, wordNext, myCompare, hash2)) = *(int*)atMap(hashTable, wordNext, myCompare, hash2)+1;
            }
        }
    }
	/*... concordance code ends here ...*/

	printMap(hashTable, keyPrint, valPrint);

	fclose(fileptr);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

  assert(containsKey(hashTable, "and", myCompare, hash2));
	removeKey(hashTable, "and", myCompare, hash2);
	removeKey(hashTable, "me", myCompare, hash2);
	removeKey(hashTable, "the", myCompare, hash2);
	
    /* printMap(hashTable); */
    printKeyValues(hashTable, keyPrint, valPrint);

    /* For Tag Cloud */
    generateTagCloudData(hashTable,"tag.csv");

    /* Free up our keys and values using our iterator!!  Also printing them as we go along */
    struct mapItr *myItr = createMapIterator(hashTable);
    while(hasNextMap(myItr)) {
        key = nextMap(myItr);
        int *value = atMap(hashTable,key, myCompare, hash2);
        printf("Freeing ...Key = %s, value = %d \n", key, *value);
        free(value);  /* To match the malloc above*/
        free(key);
    }

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}