// Token: 0x060035BA RID: 13754 RVA: 0x000F4200 File Offset: 0x000F2400
        internal SplayTreeNode GetSiblingAtOffset(int offset, out int nodeOffset)
        {
            SplayTreeNode splayTreeNode = this;

            nodeOffset = 0;
            int leftSymbolCount;

            for (;;)
            {
                leftSymbolCount = splayTreeNode.LeftSymbolCount;
                if (offset < nodeOffset + leftSymbolCount)
                {
                    splayTreeNode = splayTreeNode.LeftChildNode;
                }
                else
                {
                    int symbolCount = splayTreeNode.SymbolCount;
                    if (offset <= nodeOffset + leftSymbolCount + symbolCount)
                    {
                        break;
                    }
                    nodeOffset   += leftSymbolCount + symbolCount;
                    splayTreeNode = splayTreeNode.RightChildNode;
                }
            }
            nodeOffset += leftSymbolCount;
            splayTreeNode.Splay();
            return(splayTreeNode);
        }
        // Token: 0x060035BB RID: 13755 RVA: 0x000F425C File Offset: 0x000F245C
        internal SplayTreeNode GetSiblingAtCharOffset(int charOffset, out int nodeCharOffset)
        {
            SplayTreeNode splayTreeNode = this;

            nodeCharOffset = 0;
            int leftCharCount;

            for (;;)
            {
                leftCharCount = splayTreeNode.LeftCharCount;
                if (charOffset < nodeCharOffset + leftCharCount)
                {
                    splayTreeNode = splayTreeNode.LeftChildNode;
                }
                else if (charOffset == nodeCharOffset + leftCharCount && charOffset > 0)
                {
                    splayTreeNode = splayTreeNode.LeftChildNode;
                }
                else
                {
                    int imecharCount = splayTreeNode.IMECharCount;
                    if (imecharCount > 0 && charOffset <= nodeCharOffset + leftCharCount + imecharCount)
                    {
                        break;
                    }
                    nodeCharOffset += leftCharCount + imecharCount;
                    splayTreeNode   = splayTreeNode.RightChildNode;
                }
            }
            nodeCharOffset += leftCharCount;
            splayTreeNode.Splay();
            return(splayTreeNode);
        }
        // Token: 0x060035C4 RID: 13764 RVA: 0x000F44EC File Offset: 0x000F26EC
        internal void InsertAtNode(SplayTreeNode location, bool insertBefore)
        {
            Invariant.Assert(this.ParentNode == null, "Can't insert child node!");
            Invariant.Assert(this.LeftChildNode == null, "Can't insert node with left children!");
            Invariant.Assert(this.RightChildNode == null, "Can't insert node with right children!");
            SplayTreeNode splayTreeNode = insertBefore ? location.GetPreviousNode() : location;
            SplayTreeNode rightSubTree;
            SplayTreeNode parentNode;

            if (splayTreeNode != null)
            {
                rightSubTree = splayTreeNode.Split();
                parentNode   = splayTreeNode.ParentNode;
            }
            else
            {
                rightSubTree = location;
                location.Splay();
                Invariant.Assert(location.Role == SplayTreeNodeRole.LocalRoot, "location should be local root!");
                parentNode = location.ParentNode;
            }
            SplayTreeNode.Join(this, splayTreeNode, rightSubTree);
            this.ParentNode = parentNode;
            if (parentNode != null)
            {
                parentNode.ContainedNode = this;
            }
        }
Beispiel #4
0
        // Inserts a node before or after an existing node.
        // The new node becomes the local root.
        internal void InsertAtNode(SplayTreeNode location, bool insertBefore)
        {
            SplayTreeNode leftSubTree;
            SplayTreeNode rightSubTree;
            SplayTreeNode containingNode;

            Invariant.Assert(this.ParentNode == null, "Can't insert child node!");
            Invariant.Assert(this.LeftChildNode == null, "Can't insert node with left children!");
            Invariant.Assert(this.RightChildNode == null, "Can't insert node with right children!");

            leftSubTree = insertBefore ? location.GetPreviousNode() : location;
            if (leftSubTree != null)
            {
                rightSubTree   = leftSubTree.Split();
                containingNode = leftSubTree.ParentNode;
            }
            else
            {
                rightSubTree = location;

                location.Splay();
                Invariant.Assert(location.Role == SplayTreeNodeRole.LocalRoot, "location should be local root!");
                containingNode = location.ParentNode;
            }

            // Merge everything into a new tree.
            Join(this, leftSubTree, rightSubTree);

            // Hook up the new tree to the containing node.
            this.ParentNode = containingNode;
            if (containingNode != null)
            {
                containingNode.ContainedNode = this;
            }
        }
        // Token: 0x060035CA RID: 13770 RVA: 0x000F4770 File Offset: 0x000F2970
        internal SplayTreeNode GetMaxSibling()
        {
            SplayTreeNode splayTreeNode = this;

            for (;;)
            {
                SplayTreeNode rightChildNode = splayTreeNode.RightChildNode;
                if (rightChildNode == null)
                {
                    break;
                }
                splayTreeNode = rightChildNode;
            }
            splayTreeNode.Splay();
            return(splayTreeNode);
        }
        // Token: 0x060035C9 RID: 13769 RVA: 0x000F474C File Offset: 0x000F294C
        internal SplayTreeNode GetMinSibling()
        {
            SplayTreeNode splayTreeNode = this;

            for (;;)
            {
                SplayTreeNode leftChildNode = splayTreeNode.LeftChildNode;
                if (leftChildNode == null)
                {
                    break;
                }
                splayTreeNode = leftChildNode;
            }
            splayTreeNode.Splay();
            return(splayTreeNode);
        }
        // Token: 0x060035C1 RID: 13761 RVA: 0x000F43D0 File Offset: 0x000F25D0
        internal int GetSymbolOffset(uint treeGeneration)
        {
            int           num           = 0;
            SplayTreeNode splayTreeNode = this;

            while (splayTreeNode.Generation != treeGeneration || splayTreeNode.SymbolOffsetCache < 0)
            {
                splayTreeNode.Splay();
                num += splayTreeNode.LeftSymbolCount;
                num++;
                splayTreeNode = splayTreeNode.ParentNode;
            }
            num                   += splayTreeNode.SymbolOffsetCache;
            this.Generation        = treeGeneration;
            this.SymbolOffsetCache = num;
            return(num);
        }
        // Token: 0x060035C2 RID: 13762 RVA: 0x000F442C File Offset: 0x000F262C
        internal int GetIMECharOffset()
        {
            int           num           = 0;
            SplayTreeNode splayTreeNode = this;

            for (;;)
            {
                splayTreeNode.Splay();
                num          += splayTreeNode.LeftCharCount;
                splayTreeNode = splayTreeNode.ParentNode;
                if (splayTreeNode == null)
                {
                    break;
                }
                TextTreeTextElementNode textTreeTextElementNode = splayTreeNode as TextTreeTextElementNode;
                if (textTreeTextElementNode != null)
                {
                    num += textTreeTextElementNode.IMELeftEdgeCharCount;
                }
            }
            return(num);
        }
        // Token: 0x060035C0 RID: 13760 RVA: 0x000F4378 File Offset: 0x000F2578
        internal SplayTreeNode GetNextNode()
        {
            SplayTreeNode splayTreeNode = this.RightChildNode;

            if (splayTreeNode != null)
            {
                for (;;)
                {
                    SplayTreeNode leftChildNode = splayTreeNode.LeftChildNode;
                    if (leftChildNode == null)
                    {
                        break;
                    }
                    splayTreeNode = leftChildNode;
                }
            }
            else
            {
                SplayTreeNodeRole role = this.Role;
                splayTreeNode = this.ParentNode;
                while (role != SplayTreeNodeRole.LocalRoot)
                {
                    if (role == SplayTreeNodeRole.LeftChild)
                    {
                        goto IL_41;
                    }
                    role          = splayTreeNode.Role;
                    splayTreeNode = splayTreeNode.ParentNode;
                }
                splayTreeNode = null;
            }
IL_41:
            if (splayTreeNode != null)
            {
                splayTreeNode.Splay();
            }
            return(splayTreeNode);
        }
Beispiel #10
0
        // Inserts a node before or after an existing node. 
        // The new node becomes the local root.
        internal void InsertAtNode(SplayTreeNode location, bool insertBefore)
        {
            SplayTreeNode leftSubTree; 
            SplayTreeNode rightSubTree;
            SplayTreeNode containingNode; 
 
            Invariant.Assert(this.ParentNode == null, "Can't insert child node!");
            Invariant.Assert(this.LeftChildNode == null, "Can't insert node with left children!"); 
            Invariant.Assert(this.RightChildNode == null, "Can't insert node with right children!");

            leftSubTree = insertBefore ? location.GetPreviousNode() : location;
            if (leftSubTree != null) 
            {
                rightSubTree = leftSubTree.Split(); 
                containingNode = leftSubTree.ParentNode; 
            }
            else 
            {
                rightSubTree = location;

                location.Splay(); 
                Invariant.Assert(location.Role == SplayTreeNodeRole.LocalRoot, "location should be local root!");
                containingNode = location.ParentNode; 
            } 

            // Merge everything into a new tree. 
            Join(this, leftSubTree, rightSubTree);

            // Hook up the new tree to the containing node.
            this.ParentNode = containingNode; 
            if (containingNode != null)
            { 
                containingNode.ContainedNode = this; 
            }
        } 
Beispiel #11
0
 // Updates the SymbolCount for node's container nodes -- all the way to the TextTree root.
 private void UpdateContainerSymbolCount(SplayTreeNode containingNode, int symbolCount, int charCount) 
 { 
     do
     { 
         containingNode.Splay();
         containingNode.SymbolCount += symbolCount;
         containingNode.IMECharCount += charCount;
         containingNode = containingNode.ParentNode; 
     }
     while (containingNode != null); 
 } 
Beispiel #12
0
        // Splits a sibling tree into three sub trees -- a tree with content before startPosition,
        // a tree with content between startPosition/endPosition, and a tree with content following endPosition. 
        // Any of the subtrees may be null on exit, if they contain no content (eg, if
        // startPosition == endPosition, middleSubTree will be null on exit, and so forth).
        //
        // All returned roots have null ParentNode pointers -- the caller MUST 
        // reparent all of them, even if deleting content, to ensure orphaned
        // TextPositions can find their way back to the original tree. 
        // 
        // Returns the symbol count of middleSubTree -- all the content between startPosition and endPosition.
        private int CutContent(TextPointer startPosition, TextPointer endPosition, out int charCount, out SplayTreeNode leftSubTree, out SplayTreeNode middleSubTree, out SplayTreeNode rightSubTree) 
        {
            SplayTreeNode childNode;
            int symbolCount;
 
            Invariant.Assert(startPosition.GetScopingNode() == endPosition.GetScopingNode(), "startPosition/endPosition not in same sibling tree!");
            Invariant.Assert(startPosition.CompareTo(endPosition) != 0, "CutContent doesn't expect empty span!"); 
 
            // Get the root of all nodes to the left of the split.
            switch (startPosition.Edge) 
            {
                case ElementEdge.BeforeStart:
                    leftSubTree = startPosition.Node.GetPreviousNode();
                    break; 

                case ElementEdge.AfterStart: 
                    leftSubTree = null; 
                    break;
 
                case ElementEdge.BeforeEnd:
                default:
                    Invariant.Assert(false, "Unexpected edge!"); // Should have gone to simple insert case.
                    leftSubTree = null; 
                    break;
 
                case ElementEdge.AfterEnd: 
                    leftSubTree = startPosition.Node;
                    break; 
            }

            // Get the root of all nodes to the right of the split.
            switch (endPosition.Edge) 
            {
                case ElementEdge.BeforeStart: 
                    rightSubTree = endPosition.Node; 
                    break;
 
                case ElementEdge.AfterStart:
                default:
                    Invariant.Assert(false, "Unexpected edge! (2)"); // Should have gone to simple insert case.
                    rightSubTree = null; 
                    break;
 
                case ElementEdge.BeforeEnd: 
                    rightSubTree = null;
                    break; 

                case ElementEdge.AfterEnd:
                    rightSubTree = endPosition.Node.GetNextNode();
                    break; 
            }
 
            // Get the root of all nodes covered by startPosition/endPosition. 
            if (rightSubTree == null)
            { 
                if (leftSubTree == null)
                {
                    middleSubTree = startPosition.GetScopingNode().ContainedNode;
                } 
                else
                { 
                    middleSubTree = leftSubTree.GetNextNode(); 
                }
            } 
            else
            {
                middleSubTree = rightSubTree.GetPreviousNode();
                if (middleSubTree == leftSubTree) 
                {
                    middleSubTree = null; 
                } 
            }
 
            // Split the tree into three sub trees matching the roots we've found.

            if (leftSubTree != null)
            { 
                leftSubTree.Split();
                Invariant.Assert(leftSubTree.Role == SplayTreeNodeRole.LocalRoot); 
                leftSubTree.ParentNode.ContainedNode = null; 
                leftSubTree.ParentNode = null;
            } 

            symbolCount = 0;
            charCount = 0;
 
            if (middleSubTree != null)
            { 
                if (rightSubTree != null) 
                {
                    // Split will move middleSubTree up to the root. 
                    middleSubTree.Split();
                }
                else
                { 
                    // Make sure middleSubTree is a root.
                    middleSubTree.Splay(); 
                } 
                Invariant.Assert(middleSubTree.Role == SplayTreeNodeRole.LocalRoot, "middleSubTree is not a local root!");
 
                if (middleSubTree.ParentNode != null)
                {
                    middleSubTree.ParentNode.ContainedNode = null;
                    middleSubTree.ParentNode = null; 
                }
 
                // Calc the symbol count of the middle tree. 
                for (childNode = middleSubTree; childNode != null; childNode = childNode.RightChildNode)
                { 
                    symbolCount += childNode.LeftSymbolCount + childNode.SymbolCount;
                    charCount += childNode.LeftCharCount + childNode.IMECharCount;
                }
            } 

            if (rightSubTree != null) 
            { 
                // Make sure rightSubTree is a root before returning.
                // We haven't done anything yet to ensure this. 
                rightSubTree.Splay();
            }

            Invariant.Assert(leftSubTree == null || leftSubTree.Role == SplayTreeNodeRole.LocalRoot); 
            Invariant.Assert(middleSubTree == null || middleSubTree.Role == SplayTreeNodeRole.LocalRoot);
            Invariant.Assert(rightSubTree == null || rightSubTree.Role == SplayTreeNodeRole.LocalRoot); 
 
            return symbolCount;
        }