public void Remove(Transaction trans, int index) { if (!_isLeaf) { throw new InvalidOperationException(); } PrepareWrite(trans); SetStateDirty(); object obj = null; BTreePatch patch = KeyPatch(index); if (patch == null) { obj = _keys[index]; } else { BTreePatch transPatch = patch.ForTransaction(trans); if (transPatch != null) { obj = transPatch.GetObject(); } else { // There could be more than one patch with different object // identities. We have no means to determine a "best" object // so we just take any one. Could be problematic. obj = patch.GetObject(); } } Remove(trans, obj, index); }
public bool Remove(Transaction trans, object obj, int index) { if (!_isLeaf) { throw new InvalidOperationException(); } PrepareWrite(trans); SetStateDirty(); BTreePatch patch = KeyPatch(index); // no patch, no problem, can remove if (patch == null) { _keys[index] = ApplyNewRemovePatch(trans, obj); KeyChanged(trans, index); return(true); } BTreePatch transPatch = patch.ForTransaction(trans); if (transPatch != null) { if (transPatch.IsAdd()) { CancelAdding(trans, index); return(true); } if (transPatch.IsCancelledRemoval()) { BTreeRemove removePatch = ApplyNewRemovePatch(trans, transPatch.GetObject()); _keys[index] = ((BTreeUpdate)patch).ReplacePatch(transPatch, removePatch); KeyChanged(trans, index); return(true); } } else { // If the patch is a removal of a cancelled removal for another // transaction, we need one for this transaction also. if (!patch.IsAdd()) { ((BTreeUpdate)patch).Append(ApplyNewRemovePatch(trans, obj)); return(true); } } return(false); }