public virtual void Delete(IPersistentStore store, NodeAVL x) { if (x != null) { Monitor.Enter(this._lock); store.LockStore(); try { NodeAVL parent; if (x.GetLeft(store) == null) { parent = x.GetRight(store); } else if (x.GetRight(store) == null) { parent = x.GetLeft(store); } else { NodeAVL node = x; x = x.GetLeft(store); while (true) { NodeAVL right = x.GetRight(store); if (right == null) { break; } x = right; } parent = x.GetLeft(store); int balance = x.GetBalance(store); x = x.SetBalance(store, node.GetBalance(store)); node = node.SetBalance(store, balance); NodeAVL eavl3 = x.GetParent(store); NodeAVL n = node.GetParent(store); if (node.IsRoot(store)) { store.SetAccessor(this, x); } x = x.SetParent(store, n); if (n != null) { if (!n.IsRight(node)) { n.SetLeft(store, x); } else { n.SetRight(store, x); } } if (node.Equals(eavl3)) { node = node.SetParent(store, x); if (node.IsLeft(x)) { x = x.SetLeft(store, node); NodeAVL right = node.GetRight(store); x = x.SetRight(store, right); } else { x = x.SetRight(store, node); NodeAVL left = node.GetLeft(store); x = x.SetLeft(store, left); } } else { node = node.SetParent(store, eavl3); eavl3 = eavl3.SetRight(store, node); NodeAVL left = node.GetLeft(store); NodeAVL right = node.GetRight(store); x = x.SetLeft(store, left); x = x.SetRight(store, right); } x.GetRight(store).SetParent(store, x); x.GetLeft(store).SetParent(store, x); node = node.SetLeft(store, parent); if (parent != null) { parent = parent.SetParent(store, node); } x = node.SetRight(store, null); } bool isleft = x.IsFromLeft(store); x.Replace(store, this, parent); parent = x.GetParent(store); x.Delete(); while (parent != null) { NodeAVL eavl10; int balance; NodeAVL eavl12; x = parent; int b = isleft ? 1 : -1; switch ((x.GetBalance(store) * b)) { case -1: x = x.SetBalance(store, 0); goto Label_0359; case 0: x = x.SetBalance(store, b); return; case 1: { eavl10 = x.Child(store, !isleft); balance = eavl10.GetBalance(store); if ((balance * b) < 0) { goto Label_02B7; } x.Replace(store, this, eavl10); NodeAVL n = eavl10.Child(store, isleft); x = x.Set(store, !isleft, n); eavl10 = eavl10.Set(store, isleft, x); if (balance != 0) { break; } x = x.SetBalance(store, b); eavl10 = eavl10.SetBalance(store, -b); return; } default: goto Label_0359; } x = x.SetBalance(store, 0); x = eavl10.SetBalance(store, 0); goto Label_0359; Label_02B7: eavl12 = eavl10.Child(store, isleft); x.Replace(store, this, eavl12); balance = eavl12.GetBalance(store); eavl10 = eavl10.Set(store, isleft, eavl12.Child(store, !isleft)); eavl12 = eavl12.Set(store, !isleft, eavl10); x = x.Set(store, !isleft, eavl12.Child(store, isleft)); eavl12 = eavl12.Set(store, isleft, x); x = x.SetBalance(store, (balance == b) ? -b : 0); eavl10 = eavl10.SetBalance(store, (balance == -b) ? b : 0); x = eavl12.SetBalance(store, 0); Label_0359: isleft = x.IsFromLeft(store); parent = x.GetParent(store); } } finally { store.UnlockStore(); Monitor.Exit(this._lock); } } }