public bool Delete(Key k) { if (k == Inf1 || k == Inf2) { return(false); //or throw new Exception("Wrong key"); } Internal gp = null, p = null; Leaf l = null; Update pupdate = null, gpupdate = null, result = null; DInfo op = null; while (true) { (gp, p, l, pupdate, gpupdate) = Search(k); if (l.key != k) { return(false); } if (gpupdate.state != States.Clean) { Help(gpupdate); } else if (pupdate.state != States.Clean) { Help(pupdate); } else { op = new DInfo(gp, p, l, pupdate, null); op.myUpdate = new Update(States.DFlag, op); result = Interlocked.CompareExchange(ref gp.update, op.myUpdate, gpupdate); if (result == gpupdate) { if (HelpDelete(op)) { return(true); } } else { Help(result); } } } }
private void HelpMarked(DInfo op) { Node other; if (op.p.right == op.l) { other = op.p.left; } else { other = op.p.right; } CAS_Child(ref op.gp, op.p, other); Interlocked.CompareExchange(ref op.gp.update, new Update(States.Clean, op), op.myUpdate); }
private bool HelpDelete(DInfo op) { Update result = null; result = Interlocked.CompareExchange(ref op.p.update, new Update(States.Mark, op), op.pupdate); if (result == op.pupdate || (result.state == States.Mark && result.info == op)) { HelpMarked(op); return(true); } else { Help(result); Interlocked.CompareExchange(ref op.gp.update, new Update(States.Clean, op), op.myUpdate); return(false); } }