// ********************************************************** // Delete a record from a page. Returns OK if everything went okay. // Compacts remaining records but leaves a hole in the slot array. // Use memmove() rather than memcpy() as space may overlap. Status HFPage::deleteRecord(const RID& rid) { // fill in the body //--- deal with errors ---- if(rid.pageNo < 0 || rid.slotNo < 0) return MINIBASE_FIRST_ERROR(HEAPFILE, INVALID_SLOTNO); //return FAIL; if(rid.slotNo >= this->slotCnt) return MINIBASE_FIRST_ERROR(HEAPFILE, INVALID_SLOTNO); //return FAIL; //--- deal with empty page case --- if(empty()) return MINIBASE_FIRST_ERROR(HEAPFILE, NO_RECORDS); //return FAIL; //--- get record offset --- int offset = getRecordOffset(rid); //--- clean corresponding slot & get record length--- int len = cleanSlot(rid); //--- deal with already deleted case --- if(offset == INVALID_SLOT || len == EMPTY_SLOT) return MINIBASE_FIRST_ERROR(HEAPFILE, ALREADY_DELETED); //return FAIL; //-- shrink slot directory --- shrinkSlotDir(); //--- delete record & relocate behind records & slot dir --- //--- & update usedPtr, freeSpace ----- deleteRec(offset, len); return OK; }
// ********************************************************** // Delete a record from a page. Returns OK if everything went okay. // Compacts remaining records but leaves a hole in the slot array. // Use memmove() rather than memcpy() as space may overlap. Status HFPage::deleteRecord(const RID& rid) { // fill in the body //---?? 注意未处理delete不存在record得特殊情况---- //--- get record offset --- int offset = getRecordOffset(rid); //--- clean corresponding slot & get record length--- int len = cleanSlot(rid); //-- shrink slot directory --- shrinkSlotDir(); //--- delete record & relocate behind records & slot dir --- //--- & update usedPtr, freeSpace ----- deleteRec(offset, len); return OK; }