DBMS Requirements: HashTable
Class HashTable {
bool connect(const char* aUserName, const char* aPassword);
bool disconnect();
bool openTable(const char* aTableName);
bool hash();
void* find(int aValue);
bool closeTable();
}
HashTable Guidelines
- Assume table has only one field of type integer.
- Use DBAPI classes to implement the above methods.
- hash() method should retrieve all the record pointers using table->fetch() and hash it .
- Based on the table->numTuples(), compute bucket size.
- find(value) should return pointer to the record where the passed value is stored.
%%
HashTable Usage
int main() {
bool ret;
HashTable sTable;
ret = sTable.connect("root", "manager");
ret = sTable.openTable("T1");
sTable.hash();
void* record = sTable.find(102);
printf("Record ptr is %x and value is %d\n", record, *(int*) record);
sTable.closeTable();
sTable.disconnect();
return 0;
}
Assumption: Table T1 with field f1 of type int already exists in database