Question: 2.0 Requirements The student shall define, develop, document, prototype, test, and modify as required the software system. 2.1 Functional Requirements 2.1.1 The software shall include
| 2.0 Requirements | ||
| The student shall define, develop, document, prototype, test, and modify as required the software system. | ||
| 2.1 Functional Requirements | ||
| 2.1.1 The software shall include three functions each of which implements a different hash function. Hash functions may be those studied in class or adaptations of those functions. | ||
| 2.1.2 The software shall include three functions each of which implements a different double hash function. One and only one of these double hash functions must be for linear probing, i.e. returns an increment value of 1. | ||
| In class we used Base-26, Folding, Middle Squaring, Truncation, and Division methods for hash functions. My instructor provided these code snippets to get us started: /* --- Snippet 1: Partial list of variables defined in main() --- */ int i, hashNum, dHashNum, count; ifstream *inFile; HashStruct T[100]; // Hash table srray of 100 data structures char line[64];// Array to hold lines read from file char key[5]; // Array to hold 4-character keys int data; // Integer data /* --- Snippet 2: The following code can be used to perform the 9 tests. Use hashNum to increment a loop for each of 3 hash functions and dHashNum to increment a nested loop for each of 3 double hash functions. --- */ // For each of three hash functions for(hashNum = 0; hashNum < 3; hashNum++) { // For each of three double hash functions for(dHashNum = 0; dHashNum < 3; dHashNum++) { InitTable(T, TABLESIZE); // Call function to initialize table to empty inFile = new ifstream(); inFile->open(filename, ifstream::in); // Open data file for this test if(!inFile->is_open()) { cout << "Unable to open data file. Program terminating "; return; } count = 0; // Initialize collision counter for(int i = 0; i < 50; i++) { infile->getline(line, 64, ' '); sscanf(line, "%s %d", key, &data); count += HashInsert(T, key, data, hashNum, dHashNum); // Note: The HashInsert() function uses the indices of hashNum and // dHashNum to know which hash function and double hash function to call // in this test. } infile->close(); /* Close the text file */ delete infile; } } //============================================================================== /* --- Snippet 3: This code shows how to create a diagram of the results of a single test using one hash function and one double hash function. The resulting diagram looks similar to the sample below with '|' representing a slot where a key hashed or double hashed to and '-' representing an empty slot: ||-||||---|||-|-||||||||-----||-|-||---||||--|-|||...etc. --- */ cout << "Testing hash function " << hashNum << " using double hash " << dHashNum << ". "; cout << "Total collisions = " << count << ". "; // Show the form of the array for(int i=0; i < 100; i++) if(strcmp(T[i].key, EMPTYKEY)) // strcmp gives a non-zero (true) result if Key is NOT the EMPTYKEY cout << "|"; // Indicate an entry at this location else cout << "-"; // Indicate no entry at this location cout << " "; /* --- Snippet 4: Initialize table function --- */ void InitTable(HashStruct hashT[], int TableSize) { int i; for(i=0; i | ||
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
