DBMS Requirements: SortTable
Class SortTable {
bool connect(const char* aUserName, const char* aPassword);
bool disconnect();
bool openTable(const char* aTableName);
void setDistinct();
bool sort();
void* fetch();
bool closeTable();
}
SortTable Guidelines
- Assume table has only one field of type integer.
- Use DBAPI classes to implement the above methods.
- sort() method should retrieve all the record pointers using table->fetch() and sort it.
- Based on the table->numTuples(), compute total memory required and allocate using malloc() to store the record pointers during sort().
- fetch() should return pointer to the first element in the sorted array. Subsequent fetch() should return the next element and so on.
- If setDistinct() method is called before calling sort(), then sorted array should not have duplicate entries. It needs to be discarded.
- Implement atleast two sorting algorithms and give performance comparision with the two algorithms used.
%%
SortTable Usage
int main() {
bool ret;
SortTable sTable;
ret = sTable.connect("root", "manager");
ret = sTable.openTable("T1");
sTable.setDistinct();
sTable.sort();
void* record;
printf("Sorted Records\n");
while (true) {
record = sTable.fetch();
if (record == NULL) break;
printf("Record Value %d\n", *(int*) record);
}
sTable.closeTable();
sTable.disconnect();
return 0;
}
Assumption: Table T1 with field f1 of type int already exists in database.