/// <summary> /// Delete this node and free space /// </summary> public bool Delete() { //VSDebug.StopPoint(this.ID, 41); bool root_deleted = ((PARENT == 0) & (LEFT == 0) & (RIGHT == 0)); sp.Free(ALLOCATION); ALLOCATION = null; return(root_deleted); }
/// <summary> /// Delete index /// </summary> internal void purge() { if (ALLOCATION == null) { return; } // Delete all cross-references if (POOL > 0) { sp.ReleasePool(POOL); // Delete all nodes } sp.Free(ALLOCATION); // Delete descriptor ALLOCATION = null; }
/// <summary> /// Delete existing ID /// </summary> /// <param name="sid"></param> public int Delete(long key) { // Get key long[] keyloc = SearchKey(key); if (keyloc[0] == 0) { return(-1); } // Delete key in the block long addr = keyloc[2] * KeyBlockDef.BLOCK_ITEM_LENGTH; KeyBlockAllocWrite.Write(addr + KeyBlockDef.A_Address, KeyBlockDef.KEY_DELETED); // Update descriptor (not last key) if (KeyDescriptor[keyloc[1]].Used > 1) { KeyDescriptor[keyloc[1]].Used--; addr = keyloc[1] * KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH; KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_Used, KeyDescriptor[keyloc[1]].Used); } // If last key in the block - free block else { KeyBlockReadIndex = -1; KeyBlockAllocRead = null; sp.Free(KeyBlockAllocWrite, false); KeyDescriptor[keyloc[1]].Used = 0; KeyDescriptor[keyloc[1]].Address = 0; KeyDescriptor[keyloc[1]].FirstKey = 0; addr = keyloc[1] * KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH; KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_Used, KeyDescriptor[keyloc[1]].Used); KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_Address, KeyDescriptor[keyloc[1]].Address); KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_FirstKey, KeyDescriptor[keyloc[1]].FirstKey); KeyHeader.DescriptorUsed--; KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorUsed, KeyHeader.DescriptorUsed); for (int i = 0; i < KeyHeader.DescriptorLength; i++) { if (KeyDescriptor[i].Address == 0) { for (int j = i + 1; j < KeyHeader.DescriptorLength; j++) { if (KeyDescriptor[j].Address != 0) { KeyDescriptor[i].Address = KeyDescriptor[j].Address; KeyDescriptor[i].FirstKey = KeyDescriptor[j].FirstKey; KeyDescriptor[i].Used = KeyDescriptor[j].Used; KeyDescriptor[j].Address = 0; KeyDescriptor[j].FirstKey = 0; KeyDescriptor[j].Used = 0; break; } } } } // Update header last int save_last = KeyHeader.DescriptorLast; KeyHeader.DescriptorLast = KeyHeader.DescriptorUsed - 1; KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorLast, KeyHeader.DescriptorLast); // Rewrite header for (int i = 0; i <= save_last; i++) { addr = i * KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH; KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_Address, KeyDescriptor[i].Address); KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_FirstKey, KeyDescriptor[i].FirstKey); KeyDescriptorAlloc.Write(addr + KeyDescriptorDef.A_Used, KeyDescriptor[i].Used); } } return(0); }