예제 #1
0
string Bucket::toString(bool isRecordDataInt)
{
	string byteString("(td:");
	byteString += Utility::intToString(dispersionNumber) + ")";
	byteString += "\n";
	ListIterator<Record*> it= RecordList.getIterator();
	while(it.hasNext()){
		Record* record = it.next();
		byteString += "\t\t";
		byteString += record->getKey()->toString();
		byteString += " | ";

		if (isRecordDataInt == true)
		{
			byteString += Utility::intToString(record->getData()->readAsInt(sizeof(int)*1));
			byteString += " | ";
			byteString += Utility::intToString(record->getData()->readAsInt(sizeof(int)*0));
		}
		else
			byteString += record->getData()->toString();

		byteString += "\n";
	}
	return byteString;
}
예제 #2
0
/**
 * Searches through the pages loking for a page with enough space to store r. If no space
 * is found, it grows the segment
 *
 * @param r: the record
 *
 * @return rtrn: TID identifying the location where r was stored
 */
TID SPSegment::insert(Record& r) {

	TID rtrn;

	SlottedPage* spHolder = NULL;

	// instantiate new record pointer by given r
	Record* newRec = new Record(r.getLen(), r.getData());

	// try to find slotted page which can hold record
	for (auto it = spMap.begin(); it != spMap.end(); ++it) {

		if (it->second->getFreeSpace() >= (newRec->getLen() + (2 * sizeof(uint16_t)) + sizeof(bool))) {

			spHolder = it->second;
			rtrn.pageId = it->first;
			break;
		}
	}

	// page to hold record found
	if (spHolder != NULL) {

		// insert record into slotted page
		rtrn.slotId = spHolder->insertRecord(*newRec);

		// write changes back to disk
		if (!writeToFrame(spHolder, rtrn.pageId)) {
			cerr << "Cannot write slotted page into frame" << endl;
		}
	}
	// no page found to hold record, so increase the segment
	else {

		// just need one more page
		vector<uint64_t> neededExtents;

		// grow by 10 pages
		vector<uint64_t> newExtents = grow(10);

		// create new slotted page
		SlottedPage* sp = new SlottedPage();
		sp->getHeader()->freeSpace = bm->getPageSize() - sizeof(Header);

		rtrn.pageId = newExtents.front();
		// insert record into slotted page
		rtrn.slotId = sp->insertRecord(*newRec);

		// write changes back to disk
		if (writeToFrame(sp, rtrn.pageId)) {
			spMap[rtrn.pageId] = sp;
		} else {
			cerr << "Cannot write slotted page into frame" << endl;
		}
	}

	return rtrn;
}
예제 #3
0
int main()
{
    char fname[] = "Record.txt";
    // load record from file to vector
    vector<Record> phoneBook = getDataFromFile(fname);
    Record rec;
    int choice = menu();
    while (true){
           clearScreen;
            if (not phoneBook.empty()){
                    sort(phoneBook.begin(),phoneBook.end(),cmp);
           }
           switch(choice){
           case 1:
               rec.getData();
               phoneBook.push_back(rec);
               cout << "\nRecord added.\n" ;
               break;
           case 2:
               phoneBook = editRecord(phoneBook);
               cout << "\nRecord updated.\n" ;
               break;
           case 3:
               displayAll(phoneBook);
               break;
           case 4:
               phoneBook = deleteRecord(phoneBook);
               cout << "\nRecord deleted.\n" ;
               break;
           case 5:
               writeToFile(phoneBook,fname);
               phoneBook.clear();
               return 0;
               break;
           default :
               cout << "\nInvalid Choice ! \nRetry :\n" ;
               break;
           }
	   // wait for user
           getchar();
           clearScreen;
           choice = menu();
    }
}
예제 #4
0
bool TableScan::next() {
    if (current == ids.size())
        return false;
    else {
        registers.clear();
        Record rec = sps.lookup(ids[current++]);
        const char * data = rec.getData();
        for (auto it = schema.begin(); it != schema.end(); it++) {
            std::shared_ptr<Register> r(new Register());
            switch (it->second) {
                case Integer:
                    r->setInteger(*(reinterpret_cast<const int*> (data+it->first)));
                    break;
                case String:
                    r->setString(data+it->first);
                    break;
            }
            registers.push_back(std::move(r));
        }
        return true;
    }
}