Purpose: Use Hashing Techniques Create a ADT to handle the data in the Customer.
ID: 3825896 • Letter: P
Question
Purpose: Use Hashing Techniques Create a ADT to handle the data in the Customer.csv data file: (last,first,id) perez,diana,86824983-3587182 oxford,greg,49451687-6884854 smith,tsung,34722447-9802850 Place each ADT data object into a Hashing structure using a custom hashing function. Demonstrate you can hash the name data as key and id as value, and visa versa. One of the Keys or Values to the hash structure is required to be an ADT type. This will require overloading appropriate operators (in C++) to support the < operator. Write a hashing function that produces (ideally) a maximum of 5% collisions. Also, ideally, your space usage should be around 75% of the container.
Explanation / Answer
The Table ADT
The Table Interface
The Table interface should contain these function declarations. Note that, except for the Table_new function, they are essentially identical to those of the Set ADT from Assignment 2. One additional difference: whereas the Set_map is required to iterate over its Set's bindings in order (as determined by the compare function), the Table_map function need not iterate over its Table's bindings in any particular order.
The Table_new function should return a new Table. The parameter iBucketCount is the number of buckets that the Table will contain. The parameter pfCompare is a pointer to a compare function that the Table will use to compare keys. The function *pfCompare should return a negative integer if there is a "less than" relationship between the two given keys, a positive integer if there is a "greater than" relationship between the two given keys, and zero if the two given keys are equal. The parameter pfHash is a pointer to a hash function that the Table will use to assign bindings to buckets. It should be a checked runtime error for iBucketCount to be less than 1, for pfCompare to be NULL, or for pfHash to be NULL..
The TableIter Interface
The TableIter interface is essentially identical to that of the SetIter ADT from Assignment 3. One additional difference: whereas a SetIter is required to iterate over its Set's bindings in order (as determined by the compare function), a TableIter need not iterate over its Table's bindings in any particular order.
The Implementations
Of course you should implement your Table ADT as a hash table. Each bucket of a Table should be a Set, as specified in Assignment 2. In that manner a Table should be composed of Sets. You should use the given Set and SetIter ADTs (and not your own).
CODING IN C LANGUAGE
#include<stdio.h>
#include<conio.h>
void main() {
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int n, value;
int temp, hash;
clrscr();
printf(" Enter the value of n(table size):");
scanf("%d", &n);
do {
printf(" Enter the hash value");
scanf("%d", &value);
hash = value % n;
if (a[hash] == 0) {
a[hash] = value;
printf(" a[%d]the value %d is stored", hash, value);
} else {
for (hash++; hash < n; hash++) {
if (a[hash] == 0) {
printf("Space is allocated give other value");
a[hash] = value;
printf(" a[%d]the value %d is stored", hash, value);
goto menu;
}
}
for (hash = 0; hash < n; hash++) {
if (a[hash] == 0) {
printf("Space is allocated give other value");
a[hash] = value;
printf(" a[%d]the value %d is stored", hash, value);
goto menu;
}
}
printf(" ERROR ");
printf(" Enter '0' and press 'Enter key' twice to exit");
}
menu:
printf(" Do u want enter more");
scanf("%d", &temp);
}
while (temp == 1);
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.