コード例 #1
0
        // Token: 0x06007692 RID: 30354 RVA: 0x0021E07C File Offset: 0x0021C27C
        protected void RemoveAt(ref RBFinger <T> finger)
        {
            RBNode <T> node   = finger.Node;
            int        offset = finger.Offset;

            this.Copy(node, offset + 1, node, offset, node.Size - offset - 1);
            node.ChangeSize(-1);
            node.SetItemAt(node.Size, default(T));
            if (node.Size == 0)
            {
                finger.Node   = node.GetSuccessor();
                finger.Offset = 0;
                int        index;
                RBTree <T> rootAndIndex = node.GetRootAndIndex(node, out index);
                rootAndIndex.RemoveNode(index);
            }
            finger.Offset--;
        }
コード例 #2
0
ファイル: RBNode.cs プロジェクト: beda2280/wpf-1
        internal void InsertAt(int offset, T x, RBNode <T> successor = null, RBNode <T> succsucc = null)
        {
            if (Size < MaxSize)
            {
                // insert x into this.Array at offset
                Copy(this, offset, this, offset + 1, Size - offset);
                SetItemAt(offset, x);
                ChangeSize(1);
            }
            else
            {
                Debug.Assert(successor != null && successor.Size < MaxSize, "InsertAt: successor should have room");
                if (successor.Size == 0)
                {
                    if (succsucc == null)
                    {   // special case for insertion at the right - keep this node full
                        if (offset < MaxSize)
                        {
                            // move last item to successor
                            successor.InsertAt(0, GetItemAt(MaxSize - 1));
                            // insert x into this.Array at offset
                            Copy(this, offset, this, offset + 1, MaxSize - offset - 1);
                            SetItemAt(offset, x);
                        }
                        else
                        {
                            // insert x into successor
                            successor.InsertAt(0, x);
                        }
                    }
                    else
                    {   // split two full nodes into three
                        Debug.Assert(succsucc.Size == MaxSize, "InsertAt: outer nodes should be full");
                        int s = MaxSize / 3;

                        // move s items from this node into successor
                        Copy(successor, 0, successor, s, successor.Size);
                        Copy(this, MaxSize - s, successor, 0, s);

                        // move s items from succsucc into successor
                        Copy(succsucc, 0, successor, s + successor.Size, s);
                        Copy(succsucc, s, succsucc, 0, MaxSize - s);

                        if (offset <= MaxSize - s)
                        {
                            // insert into this.Array at offset
                            Copy(this, offset, this, offset + 1, MaxSize - s - offset);
                            SetItemAt(offset, x);

                            this.ChangeSize(1 - s);
                            successor.ChangeSize(s + s);
                        }
                        else
                        {
                            // insert into successor.Array at offset-(MaxSize-s)
                            Copy(successor, offset - (MaxSize - s), successor, offset - (MaxSize - s) + 1, successor.Size + s + s - (offset - (MaxSize - s)));
                            successor.SetItemAt(offset - (MaxSize - s), x);

                            this.ChangeSize(-s);
                            successor.ChangeSize(s + s + 1);
                        }
                        succsucc.ChangeSize(-s);
                    }
                }
                else
                {   // split a full node and its not-full successor into two pieces
                    int s = (Size + successor.Size + 1) / 2;

                    if (offset < s)
                    {
                        // move MaxSize-s+1 items from this node into successor
                        Copy(successor, 0, successor, MaxSize - s + 1, successor.Size);
                        Copy(this, s - 1, successor, 0, MaxSize - s + 1);

                        // insert into this.Array at offset
                        Copy(this, offset, this, offset + 1, s - 1 - offset);
                        SetItemAt(offset, x);
                    }
                    else
                    {
                        // move MaxSize-s items from this node into successor
                        Copy(successor, 0, successor, MaxSize - s, successor.Size);
                        Copy(this, s, successor, 0, MaxSize - s);

                        // insert into successor.Array at offset-s
                        Copy(successor, offset - s, successor, offset - s + 1, successor.Size + MaxSize - offset);
                        successor.SetItemAt(offset - s, x);
                    }
                    this.ChangeSize(s - MaxSize);
                    successor.ChangeSize(MaxSize - s + 1);
                }
            }
        }
コード例 #3
0
 // Token: 0x06007696 RID: 30358 RVA: 0x0021E1A8 File Offset: 0x0021C3A8
 internal void InsertAt(int offset, T x, RBNode <T> successor = null, RBNode <T> succsucc = null)
 {
     if (this.Size < 64)
     {
         this.Copy(this, offset, this, offset + 1, this.Size - offset);
         this.SetItemAt(offset, x);
         this.ChangeSize(1);
         return;
     }
     if (successor.Size != 0)
     {
         int num = (this.Size + successor.Size + 1) / 2;
         if (offset < num)
         {
             this.Copy(successor, 0, successor, 64 - num + 1, successor.Size);
             this.Copy(this, num - 1, successor, 0, 64 - num + 1);
             this.Copy(this, offset, this, offset + 1, num - 1 - offset);
             this.SetItemAt(offset, x);
         }
         else
         {
             this.Copy(successor, 0, successor, 64 - num, successor.Size);
             this.Copy(this, num, successor, 0, 64 - num);
             this.Copy(successor, offset - num, successor, offset - num + 1, successor.Size + 64 - offset);
             successor.SetItemAt(offset - num, x);
         }
         this.ChangeSize(num - 64);
         successor.ChangeSize(64 - num + 1);
         return;
     }
     if (succsucc != null)
     {
         int num2 = 21;
         this.Copy(successor, 0, successor, num2, successor.Size);
         this.Copy(this, 64 - num2, successor, 0, num2);
         this.Copy(succsucc, 0, successor, num2 + successor.Size, num2);
         this.Copy(succsucc, num2, succsucc, 0, 64 - num2);
         if (offset <= 64 - num2)
         {
             this.Copy(this, offset, this, offset + 1, 64 - num2 - offset);
             this.SetItemAt(offset, x);
             this.ChangeSize(1 - num2);
             successor.ChangeSize(num2 + num2);
         }
         else
         {
             this.Copy(successor, offset - (64 - num2), successor, offset - (64 - num2) + 1, successor.Size + num2 + num2 - (offset - (64 - num2)));
             successor.SetItemAt(offset - (64 - num2), x);
             this.ChangeSize(-num2);
             successor.ChangeSize(num2 + num2 + 1);
         }
         succsucc.ChangeSize(-num2);
         return;
     }
     if (offset < 64)
     {
         successor.InsertAt(0, this.GetItemAt(63), null, null);
         this.Copy(this, offset, this, offset + 1, 64 - offset - 1);
         this.SetItemAt(offset, x);
         return;
     }
     successor.InsertAt(0, x, null, null);
 }