Пример #1
0
 public static void Insert(GDFEntryNode Root, GDFDirEntry NewKey)
 {
     if (Root.Key == null)
     {
         Root.Key = NewKey;
     }
     else
     {
         int num = Root.Key.Name.CompareTo(NewKey.Name);
         if (num > 0)
         {
             if (Root.Left == null)
             {
                 Root.Left = new GDFEntryNode(Root);
             }
             Insert(Root.Left, NewKey);
         }
         else if (num < 0)
         {
             if (Root.Right == null)
             {
                 Root.Right = new GDFEntryNode(Root);
             }
             Insert(Root.Right, NewKey);
         }
     }
     if ((Root.Parent != null) && (Root.Parent.Parent != null))
     {
         Rebalance(Root.Parent.Parent, Root.Parent, GetBalance(Root));
     }
 }
Пример #2
0
        private static GDFEntryNode RotateRightLeft(GDFEntryNode Root, GDFEntryNode Pivot)
        {
            GDFEntryNode left = Pivot.Left;

            Pivot.Left = left.Right;
            Root.Right = left.Left;
            left.Right = Pivot;
            left.Left  = Root;
            if (Root.Parent == null)
            {
                left.Parent  = null;
                Root.Parent  = left;
                Pivot.Parent = left;
                return(left);
            }
            left.Parent = Root.Parent;
            if (Root.Parent.Right == Root)
            {
                Root.Parent.Right = left;
            }
            else
            {
                Root.Parent.Left = left;
            }
            Root.Parent  = left;
            Pivot.Parent = left;
            return(left);
        }
Пример #3
0
 public static void Insert(GDFEntryNode Root, GDFDirEntry NewKey)
 {
     if (Root.Key == null)
     {
         Root.Key = NewKey;
     }
     else
     {
         int num = Root.Key.Name.CompareTo(NewKey.Name);
         if (num > 0)
         {
             if (Root.Left == null)
             {
                 Root.Left = new GDFEntryNode(Root);
             }
             Insert(Root.Left, NewKey);
         }
         else if (num < 0)
         {
             if (Root.Right == null)
             {
                 Root.Right = new GDFEntryNode(Root);
             }
             Insert(Root.Right, NewKey);
         }
     }
     if ((Root.Parent != null) && (Root.Parent.Parent != null))
     {
         Rebalance(Root.Parent.Parent, Root.Parent, GetBalance(Root));
     }
 }
Пример #4
0
        private static GDFEntryNode RotateLeftRight(GDFEntryNode Root, GDFEntryNode Pivot)
        {
            GDFEntryNode right = Pivot.Right;

            Root.Left   = right.Right;
            Pivot.Right = right.Left;
            right.Left  = Pivot;
            right.Right = Root;
            if (Root.Parent == null)
            {
                right.Parent = null;
                Root.Parent  = right;
                Pivot.Parent = right;
                return(right);
            }
            right.Parent = Root.Parent;
            if (Root.Parent.Right == Root)
            {
                Root.Parent.Right = right;
            }
            else
            {
                Root.Parent.Left = right;
            }
            Root.Parent  = right;
            Pivot.Parent = right;
            return(right);
        }
Пример #5
0
 private void writeInOrder(GDFEntryNode Node, MemoryStream ms)
 {
     byte[] buffer = Node.Key.ToByteArray();
     ms.Write(buffer, 0, buffer.Length);
     if (Node.Left != null)
     {
         this.writeInOrder(Node.Left, ms);
     }
     if (Node.Right != null)
     {
         this.writeInOrder(Node.Right, ms);
     }
 }
Пример #6
0
 private void updateInOrder(GDFEntryNode Node, ref uint offset)
 {
     offset += Node.Key.EntrySize / 4;
     if (Node.Left != null)
     {
         Node.Key.SubTreeL = (ushort)offset;
         this.updateInOrder(Node.Left, ref offset);
     }
     if (Node.Right != null)
     {
         Node.Key.SubTreeR = (ushort)offset;
         this.updateInOrder(Node.Right, ref offset);
     }
 }
Пример #7
0
 public void Insert(GDFDirEntry Value)
 {
     if (this.Root == null)
     {
         this.Root = new GDFEntryNode(Value);
     }
     else
     {
         GDFEntryNode.Insert(this.Root, Value);
     }
     while (this.Root.Parent != null)
     {
         this.Root = this.Root.Parent;
     }
 }
Пример #8
0
 public void Insert(GDFDirEntry Value)
 {
     if (this.Root == null)
     {
         this.Root = new GDFEntryNode(Value);
     }
     else
     {
         GDFEntryNode.Insert(this.Root, Value);
     }
     while (this.Root.Parent != null)
     {
         this.Root = this.Root.Parent;
     }
 }
Пример #9
0
        public static GDFEntryNode Rebalance(GDFEntryNode Root, GDFEntryNode Pivot, TreeNodeBalance Balance)
        {
            switch (Balance)
            {
            case TreeNodeBalance.LeftLeft:
                return(RotateRight(Root, Pivot));

            case TreeNodeBalance.LeftRight:
                return(RotateLeftRight(Root, Pivot));

            case TreeNodeBalance.RightRight:
                return(RotateLeft(Root, Pivot));

            case TreeNodeBalance.RightLeft:
                return(RotateRightLeft(Root, Pivot));
            }
            return(null);
        }
Пример #10
0
        public static TreeNodeBalance GetBalance(GDFEntryNode Root)
        {
            int num = 0;

            if (Root.Parent != null)
            {
                if (Root.Parent.Left != null)
                {
                    num++;
                }
                if (Root.Parent.Right != null)
                {
                    num--;
                }
                if (Root.Parent.Parent != null)
                {
                    if (num > 0)
                    {
                        if ((Root.Parent.Parent.Left != null) && (Root.Parent.Parent.Right == null))
                        {
                            return(TreeNodeBalance.LeftLeft);
                        }
                        if ((Root.Parent.Parent.Right != null) && (Root.Parent.Parent.Left == null))
                        {
                            return(TreeNodeBalance.RightLeft);
                        }
                    }
                    if (num < 0)
                    {
                        if ((Root.Parent.Parent.Left != null) && (Root.Parent.Parent.Right == null))
                        {
                            return(TreeNodeBalance.LeftRight);
                        }
                        if ((Root.Parent.Parent.Right != null) && (Root.Parent.Parent.Left == null))
                        {
                            return(TreeNodeBalance.RightRight);
                        }
                    }
                }
            }
            return(TreeNodeBalance.Balanced);
        }
Пример #11
0
 public static TreeNodeBalance GetBalance(GDFEntryNode Root)
 {
     int num = 0;
     if (Root.Parent != null)
     {
         if (Root.Parent.Left != null)
         {
             num++;
         }
         if (Root.Parent.Right != null)
         {
             num--;
         }
         if (Root.Parent.Parent != null)
         {
             if (num > 0)
             {
                 if ((Root.Parent.Parent.Left != null) && (Root.Parent.Parent.Right == null))
                 {
                     return TreeNodeBalance.LeftLeft;
                 }
                 if ((Root.Parent.Parent.Right != null) && (Root.Parent.Parent.Left == null))
                 {
                     return TreeNodeBalance.RightLeft;
                 }
             }
             if (num < 0)
             {
                 if ((Root.Parent.Parent.Left != null) && (Root.Parent.Parent.Right == null))
                 {
                     return TreeNodeBalance.LeftRight;
                 }
                 if ((Root.Parent.Parent.Right != null) && (Root.Parent.Parent.Left == null))
                 {
                     return TreeNodeBalance.RightRight;
                 }
             }
         }
     }
     return TreeNodeBalance.Balanced;
 }
Пример #12
0
 private static GDFEntryNode RotateRight(GDFEntryNode Root, GDFEntryNode Pivot)
 {
     Root.Left   = null;
     Pivot.Right = Root;
     if (Root.Parent == null)
     {
         Pivot.Parent = null;
         Root.Parent  = Pivot;
         return(Pivot);
     }
     if (Root.Parent.Right == Root)
     {
         Root.Parent.Right = Pivot;
     }
     else
     {
         Root.Parent.Left = Pivot;
     }
     Root.Parent = Pivot;
     return(Pivot);
 }
Пример #13
0
 private static GDFEntryNode RotateLeftRight(GDFEntryNode Root, GDFEntryNode Pivot)
 {
     GDFEntryNode right = Pivot.Right;
     Root.Left = right.Right;
     Pivot.Right = right.Left;
     right.Left = Pivot;
     right.Right = Root;
     if (Root.Parent == null)
     {
         right.Parent = null;
         Root.Parent = right;
         Pivot.Parent = right;
         return right;
     }
     right.Parent = Root.Parent;
     if (Root.Parent.Right == Root)
     {
         Root.Parent.Right = right;
     }
     else
     {
         Root.Parent.Left = right;
     }
     Root.Parent = right;
     Pivot.Parent = right;
     return right;
 }
Пример #14
0
 private static GDFEntryNode RotateRightLeft(GDFEntryNode Root, GDFEntryNode Pivot)
 {
     GDFEntryNode left = Pivot.Left;
     Pivot.Left = left.Right;
     Root.Right = left.Left;
     left.Right = Pivot;
     left.Left = Root;
     if (Root.Parent == null)
     {
         left.Parent = null;
         Root.Parent = left;
         Pivot.Parent = left;
         return left;
     }
     left.Parent = Root.Parent;
     if (Root.Parent.Right == Root)
     {
         Root.Parent.Right = left;
     }
     else
     {
         Root.Parent.Left = left;
     }
     Root.Parent = left;
     Pivot.Parent = left;
     return left;
 }
Пример #15
0
 public GDFEntryNode(GDFEntryNode Parent)
 {
     this.Parent = Parent;
 }
Пример #16
0
        public static GDFEntryNode Rebalance(GDFEntryNode Root, GDFEntryNode Pivot, TreeNodeBalance Balance)
        {
            switch (Balance)
            {
                case TreeNodeBalance.LeftLeft:
                    return RotateRight(Root, Pivot);

                case TreeNodeBalance.LeftRight:
                    return RotateLeftRight(Root, Pivot);

                case TreeNodeBalance.RightRight:
                    return RotateLeft(Root, Pivot);

                case TreeNodeBalance.RightLeft:
                    return RotateRightLeft(Root, Pivot);
            }
            return null;
        }
Пример #17
0
 private static GDFEntryNode RotateRight(GDFEntryNode Root, GDFEntryNode Pivot)
 {
     Root.Left = null;
     Pivot.Right = Root;
     if (Root.Parent == null)
     {
         Pivot.Parent = null;
         Root.Parent = Pivot;
         return Pivot;
     }
     if (Root.Parent.Right == Root)
     {
         Root.Parent.Right = Pivot;
     }
     else
     {
         Root.Parent.Left = Pivot;
     }
     Root.Parent = Pivot;
     return Pivot;
 }
Пример #18
0
 public GDFEntryNode(GDFEntryNode Parent)
 {
     this.Parent = Parent;
 }