예제 #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;
 }