void workHard(int hashSize) { FILE *input1 = fopen("input1.txt", "r"); HashTable *table = createTable(hashSize); int counter = 0; while (!feof(input1)) { char string[1000] = {}; fgets(string, 1000, input1); if (strlen(string) < 1) break; if (counter > 0.7 * hashSize) { destroyHashTable(table); delete table; fclose(input1); //printf("REBUILD!\n"); workHard(2 * hashSize); return; } buildTable(table, string); memset(string, '\0', 1000); counter++; } fclose(input1); //printTable(table); FILE *input2 = fopen("input2.txt", "r"); FILE *output = fopen("output.txt", "w"); while (!feof(input2)) { char string[1000] = {}; fgets(string, 1000, input1); if (strlen(string) < 1) break; if (isExists(table, string)) { fputs(string, output); } memset(string, '\0', 1000); } destroyHashTable(table); delete table; fclose(input2); fclose(output); }
int main(int argc, const char * argv[]) { struct hashTable *ht; char *value; createHashTable(10, &ht); printf("Adding 'hello'=>'world', 'color'=>'blue' and printing:\n-----\n"); // add "hello" => "world", and verify assert(!valueForKeyInHashTable(ht, "hello", &value)); assert(NULL == value); assert(addToHashTable(ht, "hello", "world")); // do it once, assert(addToHashTable(ht, "hello", "world")); // then again, for good measure assert(valueForKeyInHashTable(ht, "hello", &value)); assert(0 == strcmp("world", value)); // add "color" => "blue", and verify assert(!valueForKeyInHashTable(ht, "color", &value)); assert(NULL == value); assert(addToHashTable(ht, "color", "blue")); assert(valueForKeyInHashTable(ht, "color", &value)); assert(0 == strcmp("blue", value)); // print all the values we've added assert(printAllKeysAndValues(ht)); printf("\n\nChanging 'hello' value to 'goodbye', then printing:\n-----\n"); // change "hello"'s value to "goodbye" assert(addToHashTable(ht, "hello", "goodbye")); // do it once, assert(valueForKeyInHashTable(ht, "hello", &value)); assert(0 == strcmp("goodbye", value)); // print all the values we've added assert(printAllKeysAndValues(ht)); // -- // now remove and print printf("\n\nRemoving 'hello' and printing:\n-----\n"); assert(removeFromHashTable(ht, "hello")); assert(printAllKeysAndValues(ht)); printf("\n\nRemoving 'color' and printing:\n-----\n"); assert(removeFromHashTable(ht, "color")); assert(printAllKeysAndValues(ht)); // clean up destroyHashTable(&ht); assert(NULL == ht); }
//rehash all elements from one table to another using reHash function defined above int actualRehash(HashTable *h){ //rehash every element of the table SizeOfTable = SizeOfTable * 2; HashTable newHash; initializeTable(&newHash); for (int i = 2; i < SizeOfTable/2; i++){ reHash(h,&newHash,i); } destroyHashTable(h); //destroy the old table (*h) = newHash; return 0; }
int main() { (void)setHashFunc(modeFunc); initHashTable(); test1(); test2(); test3(); destroyHashTable(); system("pause"); }
void destroyHaloExchange(HaloExchange** haloExchange) { (*haloExchange)->destroy((*haloExchange)->parms); if((*haloExchange)->hashTable); destroyHashTable(&((*haloExchange)->hashTable)); free((*haloExchange)->sendBufM); free((*haloExchange)->sendBufP); free((*haloExchange)->recvBufP); free((*haloExchange)->recvBufM); free(*haloExchange); *haloExchange = NULL; }
int main(int argc, char* argv[]) { HashTable* hashtable = createHashTable(10); int i; int* o; for(i=0; i<250; i++) { o = malloc(sizeof(int)); *o = i+1000; put(hashtable, i, o); } print_table(hashtable); o = get(hashtable, 0); printf("%d\n", *o); o = get(hashtable, 56); printf("%d\n", *o); destroyHashTable(hashtable); }
int main() { //init int N = _100000; char** hashTable; int size; char** content = readFromFile(N); //printContentToConsole(content, N); printf("ISF: %f; MFF: %f; N = %d\n", INITIAL_HT_SIZE_FACTOR, MAX_FILL_FACTOR, N); initHashTable(&hashTable, &size, N); printf("Initial Size: %d\n", size); //solution insertAllElements(&hashTable, &size, N, content); printf("terminal size: %d\n", size); destroyHashTable(&hashTable, size); return 0; }
void releaseMemo() { DEBUG("IN"); if (que) {destroyQue(que); que = NULL;} if (ht) {destroyHashTable(ht); ht = NULL;} DEBUG("OUT"); }