示例#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;
 }