コード例 #1
0
        //TODO: copy-paste, parent-setter
        protected override BaseTreapNode <T> Delete(int idx, BaseTreapNode <T> tNode)
        {
            int leftTreeCount = GetTreeLeftCount(tNode);

            if (idx < leftTreeCount)
            {
                tNode.Left = Delete(idx, tNode.Left);
                tNode.UpdateAggregate();
                return(tNode);
            }
            if (idx > leftTreeCount)
            {
                tNode.Right = Delete(idx - leftTreeCount - 1, tNode.Right);
                tNode.UpdateAggregate();
                return(tNode);
            }

            ParentTreapNode <T> node = (ParentTreapNode <T>)tNode;

            ParentTreapNode <T> parent = node.Parent;

            tNode = tNode.DeleteRoot();
            if (tNode != null)
            {
                ((ParentTreapNode <T>)tNode).Parent = parent;
            }

            return(tNode);
        }
コード例 #2
0
        public override BaseTreapNode <T> RotateRight()
        {
            ParentTreapNode <T> parent1 = parent;
            BaseTreapNode <T>   node    = base.RotateRight();

            ((ParentTreapNode <T>)node).Parent = parent1;
            return(node);
        }
コード例 #3
0
        protected override void RightSetter(BaseTreapNode <T> node)
        {
            base.RightSetter(node);
            ParentTreapNode <T> treapNode = node as ParentTreapNode <T>;

            if (treapNode != null)
            {
                treapNode.Parent = this;
            }
        }
コード例 #4
0
        public int GetInverse(ParentTreapNode <T> node)
        {
            ParentTreapNode <T> input = node;

            int res = GetTreeLeftCount(input);

            while (input.Parent != null)
            {
                ParentTreapNode <T> parent = input.Parent;

                if (ReferenceEquals(parent.Right, input))
                {
                    res += GetTreeLeftCount(parent) + 1;
                }

                input = parent;
            }

            return(res);
        }