Example #1
0
        public override void Replace(IPersistentStore store, Index index, NodeAVL n)
        {
            NodeAVLDisk node = this;
            RowAVLDisk  row  = this.row;

            if (!row.KeepInMemory(true))
            {
                row  = (RowAVLDisk)store.Get(this.row, true);
                node = (NodeAVLDisk)row.GetNode(this._iId);
            }
            if (node._iParent == -1)
            {
                if (n != null)
                {
                    n = n.SetParent(store, null);
                }
                store.SetAccessor(index, n);
            }
            else
            {
                bool isLeft = node.IsFromLeft(store);
                node.GetParent(store).Set(store, isLeft, n);
            }
            row.KeepInMemory(false);
        }
Example #2
0
 public virtual void Replace(IPersistentStore store, Index index, NodeAVL n)
 {
     if (this.nParent == null)
     {
         if (n != null)
         {
             n = n.SetParent(store, null);
         }
         store.SetAccessor(index, n);
     }
     else
     {
         this.nParent.Set(store, this.IsFromLeft(store), n);
     }
 }
Example #3
0
        public virtual void Insert(Session session, IPersistentStore store, Row row)
        {
            bool useRowId = !this.isUnique || this.HasNulls(row.RowData);

            Monitor.Enter(this._lock);
            store.LockStore();
            try
            {
                bool       flag2;
                NodeAVL    eavl2;
                Constraint uniqueConstraintForIndex;
                Row        row2;
                RowAVL     wavl     = (RowAVL)row;
                NodeAVL    accessor = this.GetAccessor(store);
                if (accessor == null)
                {
                    store.SetAccessor(this, wavl.GetNode(this.Position));
                    store.SetElementCount(this, 1, 1);
                    return;
                }
Label_005C:
                row2 = accessor.GetRow(store);
                int num = this.CompareRowForInsertOrDelete(session, row, row2, useRowId, 0);
                if ((((num == 0) && (session != null)) && (!useRowId && session.database.TxManager.IsMvRows())) && !this.IsEqualReadable(session, store, accessor))
                {
                    useRowId = true;
                    num      = this.CompareRowForInsertOrDelete(session, row, row2, useRowId, this.ColIndex.Length);
                }
                if (num != 0)
                {
                    flag2    = num < 0;
                    eavl2    = accessor;
                    accessor = eavl2.Child(store, flag2);
                    if (accessor != null)
                    {
                        goto Label_005C;
                    }
                }
                else
                {
                    uniqueConstraintForIndex = null;
                    if (this.isConstraint)
                    {
                        uniqueConstraintForIndex = ((Table)this.table).GetUniqueConstraintForIndex(this);
                    }
                    goto Label_0119;
                }
                eavl2 = eavl2.Set(store, flag2, wavl.GetNode(this.Position));
                this.Balance(store, eavl2, flag2);
                store.UpdateElementCount(this, 1, 1);
                return;

Label_0119:
                if (uniqueConstraintForIndex == null)
                {
                    throw Error.GetError(0x68, this.Name.StatementName);
                }
                throw uniqueConstraintForIndex.GetException(row.RowData);
            }
            finally
            {
                store.UnlockStore();
                Monitor.Exit(this._lock);
            }
        }
Example #4
0
        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);
                }
            }
        }
Example #5
0
        public override void Delete(IPersistentStore store, NodeAVL x)
        {
            if (x != null)
            {
                lock (base._lock)
                {
                    NodeAVL nParent;
                    if (x.nLeft == null)
                    {
                        nParent = x.nRight;
                    }
                    else if (x.nRight == null)
                    {
                        nParent = x.nLeft;
                    }
                    else
                    {
                        NodeAVL eavl2 = x;
                        x = x.nLeft;
                        while (true)
                        {
                            NodeAVL nRight = x.nRight;
                            if (nRight == null)
                            {
                                break;
                            }
                            x = nRight;
                        }
                        nParent = x.nLeft;
                        int iBalance = x.IBalance;
                        x.IBalance     = eavl2.IBalance;
                        eavl2.IBalance = iBalance;
                        NodeAVL eavl3 = x.nParent;
                        NodeAVL eavl4 = eavl2.nParent;
                        if (eavl2.IsRoot(store))
                        {
                            store.SetAccessor(this, x);
                        }
                        x.nParent = eavl4;
                        if (eavl4 != null)
                        {
                            if (eavl4.nRight == eavl2)
                            {
                                eavl4.nRight = x;
                            }
                            else
                            {
                                eavl4.nLeft = x;
                            }
                        }
                        if (eavl2 == eavl3)
                        {
                            eavl2.nParent = x;
                            if (eavl2.nLeft == x)
                            {
                                x.nLeft  = eavl2;
                                x.nRight = eavl2.nRight;
                            }
                            else
                            {
                                x.nRight = eavl2;
                                x.nLeft  = eavl2.nLeft;
                            }
                        }
                        else
                        {
                            eavl2.nParent = eavl3;
                            eavl3.nRight  = eavl2;
                            NodeAVL nLeft  = eavl2.nLeft;
                            NodeAVL nRight = eavl2.nRight;
                            x.nLeft  = nLeft;
                            x.nRight = nRight;
                        }
                        x.nRight.nParent = x;
                        x.nLeft.nParent  = x;
                        eavl2.nLeft      = nParent;
                        if (nParent != null)
                        {
                            nParent.nParent = eavl2;
                        }
                        eavl2.nRight = null;
                        x            = eavl2;
                    }
                    bool isleft = x.IsFromLeft(store);
                    x.Replace(store, this, nParent);
                    nParent = x.nParent;
                    x.Delete();
                    while (nParent != null)
                    {
                        NodeAVL eavl10;
                        int     iBalance;
                        NodeAVL eavl12;
                        x = nParent;
                        int num2 = isleft ? 1 : -1;
                        switch ((x.IBalance * num2))
                        {
                        case -1:
                            x.IBalance = 0;
                            goto Label_02E9;

                        case 0:
                            x.IBalance = num2;
                            return;

                        case 1:
                        {
                            eavl10   = x.Child(store, !isleft);
                            iBalance = eavl10.IBalance;
                            if ((iBalance * num2) < 0)
                            {
                                goto Label_0255;
                            }
                            x.Replace(store, this, eavl10);
                            NodeAVL n = eavl10.Child(store, isleft);
                            x.Set(store, !isleft, n);
                            eavl10.Set(store, isleft, x);
                            if (iBalance != 0)
                            {
                                break;
                            }
                            x.IBalance      = num2;
                            eavl10.IBalance = -num2;
                            return;
                        }

                        default:
                            goto Label_02E9;
                        }
                        x.IBalance      = 0;
                        eavl10.IBalance = 0;
                        x = eavl10;
                        goto Label_02E9;
Label_0255:
                        eavl12 = eavl10.Child(store, isleft);
                        x.Replace(store, this, eavl12);
                        iBalance = eavl12.IBalance;
                        eavl10.Set(store, isleft, eavl12.Child(store, !isleft));
                        eavl12.Set(store, !isleft, eavl10);
                        x.Set(store, !isleft, eavl12.Child(store, isleft));
                        eavl12.Set(store, isleft, x);
                        x.IBalance      = (iBalance == num2) ? -num2 : 0;
                        eavl10.IBalance = (iBalance == -num2) ? num2 : 0;
                        eavl12.IBalance = 0;
                        x = eavl12;
Label_02E9:
                        isleft  = x.IsFromLeft(store);
                        nParent = x.nParent;
                    }
                }
            }
        }
Example #6
0
        public override void Insert(Session session, IPersistentStore store, Row row)
        {
            object[] rowData  = row.RowData;
            bool     useRowId = !base.isUnique || base.HasNulls(rowData);
            bool     isSimple = base.IsSimple;

            lock (base._lock)
            {
                NodeAVL    eavl2;
                Constraint uniqueConstraintForIndex;
                RowAVL     wavl     = (RowAVL)row;
                NodeAVL    accessor = base.GetAccessor(store);
                if (accessor == null)
                {
                    store.SetAccessor(this, wavl.GetNode(base.Position));
                    store.SetElementCount(this, 1, 1);
                    goto Label_01BB;
                }
                bool isLeft = false;
                do
                {
                    if (base.ColTypes.Length != 0)
                    {
                        int num;
                        Row memoryRow = accessor.MemoryRow;
                        if (isSimple)
                        {
                            num = base.ColTypes[0].Compare(session, rowData[base.ColIndex[0]], memoryRow.RowData[base.ColIndex[0]], null, false);
                            if ((num == 0) & useRowId)
                            {
                                num = base.CompareRowForInsertOrDelete(session, row, memoryRow, useRowId, 1);
                            }
                        }
                        else
                        {
                            num = base.CompareRowForInsertOrDelete(session, row, memoryRow, useRowId, 0);
                        }
                        if ((((num == 0) && (session != null)) && (!useRowId && session.database.TxManager.IsMvRows())) && !base.IsEqualReadable(session, store, accessor))
                        {
                            useRowId = true;
                            num      = base.CompareRowForInsertOrDelete(session, row, memoryRow, useRowId, base.ColIndex.Length);
                        }
                        if (num == 0)
                        {
                            goto Label_013C;
                        }
                        isLeft = num < 0;
                    }
                    eavl2    = accessor;
                    accessor = isLeft ? eavl2.nLeft : eavl2.nRight;
                }while (accessor != null);
                goto Label_015C;
Label_013C:
                uniqueConstraintForIndex = null;
                if (base.isConstraint)
                {
                    uniqueConstraintForIndex = ((Table)base.table).GetUniqueConstraintForIndex(this);
                }
                goto Label_018A;
Label_015C:
                eavl2 = eavl2.Set(store, isLeft, wavl.GetNode(base.Position));
                this.Balance(store, eavl2, isLeft);
                store.UpdateElementCount(this, 1, 1);
                goto Label_01BB;
Label_018A:
                if (uniqueConstraintForIndex == null)
                {
                    throw Error.GetError(0x68, base.Name.StatementName);
                }
                throw uniqueConstraintForIndex.GetException(row.RowData);
                Label_01BB :;
            }
        }