Esempio n. 1
0
        public virtual NodeAVL Last(IPersistentStore store, NodeAVL x)
        {
            if (x == null)
            {
                return(null);
            }
            NodeAVL left = x.GetLeft(store);

            if (left != null)
            {
                x = left;
                for (NodeAVL eavl3 = x.GetRight(store); eavl3 != null; eavl3 = x.GetRight(store))
                {
                    x = eavl3;
                }
                return(x);
            }
            NodeAVL eavl4 = x;

            x = x.GetParent(store);
            while ((x != null) && eavl4.Equals(x.GetLeft(store)))
            {
                eavl4 = x;
                x     = x.GetParent(store);
            }
            return(x);
        }
Esempio n. 2
0
        public virtual NodeAVL Next(IPersistentStore store, NodeAVL x)
        {
            NodeAVL right = x.GetRight(store);

            if (right != null)
            {
                x = right;
                for (NodeAVL eavl3 = x.GetLeft(store); eavl3 != null; eavl3 = x.GetLeft(store))
                {
                    x = eavl3;
                }
                return(x);
            }
            NodeAVL eavl4 = x;

            x = x.GetParent(store);
            while ((x != null) && (eavl4 == x.GetRight(store)))
            {
                eavl4 = x;
                x     = x.GetParent(store);
            }
            return(x);
        }
Esempio n. 3
0
 public IRowIterator LastRow(Session session, IPersistentStore store)
 {
     lock (this._lock)
     {
         NodeAVL accessor = this.GetAccessor(store);
         for (NodeAVL eavl2 = accessor; eavl2 != null; eavl2 = accessor.GetRight(store))
         {
             accessor = eavl2;
         }
         while ((session != null) && (accessor != null))
         {
             Row row = accessor.GetRow(store);
             if (session.database.TxManager.CanRead(session, row, 0, null))
             {
                 break;
             }
             accessor = this.Last(store, accessor);
         }
         return(this.GetIterator(null, store, accessor, false, true));
     }
 }
Esempio n. 4
0
        private NodeAVL FindNode(Session session, IPersistentStore store, object[] rowdata, int[] rowColMap, int fieldCount, int compareType, int readMode, bool reversed)
        {
            NodeAVL eavl;

            lock (this._lock)
            {
                Row     row2;
                NodeAVL accessor = this.GetAccessor(store);
                NodeAVL left     = null;
                NodeAVL x        = null;
                if ((compareType != 0x29) && (compareType != 0x2f))
                {
                    fieldCount--;
                }
                while (accessor != null)
                {
                    Row row = accessor.GetRow(store);
                    int num = 0;
                    if (fieldCount > 0)
                    {
                        num = this.CompareRowNonUnique(session, row.RowData, rowdata, rowColMap, fieldCount);
                    }
                    if (num != 0)
                    {
                        goto Label_017B;
                    }
                    switch (compareType)
                    {
                    case 0x29:
                    case 0x2f:
                        x    = accessor;
                        left = accessor.GetLeft(store);
                        goto Label_0197;

                    case 0x2a:
                        if (this.CompareObject(session, row.RowData, rowdata, rowColMap, fieldCount) >= 0)
                        {
                            break;
                        }
                        left = accessor.GetRight(store);
                        goto Label_0197;

                    case 0x2b:
                    case 0x30:
                        if (this.CompareObject(session, row.RowData, rowdata, rowColMap, fieldCount) > 0)
                        {
                            goto Label_00FC;
                        }
                        left = accessor.GetRight(store);
                        goto Label_0197;

                    case 0x2c:
                        if (this.CompareObject(session, row.RowData, rowdata, rowColMap, fieldCount) >= 0)
                        {
                            goto Label_0131;
                        }
                        x    = accessor;
                        left = accessor.GetRight(store);
                        goto Label_0197;

                    case 0x2d:
                        if (this.CompareObject(session, row.RowData, rowdata, rowColMap, fieldCount) > 0)
                        {
                            goto Label_0161;
                        }
                        x    = accessor;
                        left = accessor.GetRight(store);
                        goto Label_0197;

                    default:
                        throw Error.RuntimeError(0xc9, "Index");
                    }
                    x    = accessor;
                    left = accessor.GetLeft(store);
                    goto Label_0197;
Label_00FC:
                    x    = accessor;
                    left = accessor.GetLeft(store);
                    goto Label_0197;
Label_0131:
                    left = accessor.GetLeft(store);
                    goto Label_0197;
Label_0161:
                    left = accessor.GetLeft(store);
                    goto Label_0197;
Label_017B:
                    if (num < 0)
                    {
                        left = accessor.GetRight(store);
                    }
                    else if (num > 0)
                    {
                        left = accessor.GetLeft(store);
                    }
Label_0197:
                    if (left == null)
                    {
                        break;
                    }
                    accessor = left;
                }
                if (session != null)
                {
                    goto Label_0210;
                }
                return(x);

Label_01A9:
                row2 = x.GetRow(store);
                if (session.database.TxManager.CanRead(session, row2, readMode, this.ColIndex))
                {
                    goto Label_0213;
                }
                x = reversed ? this.Last(store, x) : this.Next(store, x);
                if (x == null)
                {
                    goto Label_0213;
                }
                row2 = x.GetRow(store);
                if ((fieldCount > 0) && (this.CompareRowNonUnique(session, row2.RowData, rowdata, rowColMap, fieldCount) != 0))
                {
                    x = null;
                    goto Label_0213;
                }
Label_0210:
                if (x != null)
                {
                    goto Label_01A9;
                }
Label_0213:
                eavl = x;
            }
            return(eavl);
        }
Esempio n. 5
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);
                }
            }
        }