Exemple #1
0
        } // end constructor

        // insert TreeNode into Tree that contains nodes;
        // ignore duplicate values
        public void Insert(int insertValue)
        {
            if (insertValue < Data) // insert in left subtree
            {
                // insert new TreeNode
                if (LeftNode == null)
                {
                    LeftNode = new TreeNode(insertValue);
                }
                else // continue traversing left subtree
                {
                    LeftNode.Insert(insertValue);
                }
            } // end if
            else if (insertValue > Data) // insert in right subtree
            {
                // insert new TreeNode
                if (RightNode == null)
                {
                    RightNode = new TreeNode(insertValue);
                }
                else // continue traversing right subtree
                {
                    RightNode.Insert(insertValue);
                }
            } // end else if
        }     // end method Insert
Exemple #2
0
 // insert TreeNode into Tree that contains nodes;
 // ignore duplicate values
 public void Insert(T insertValue)
 {
     if (insertValue.CompareTo(Data) < 0) // insert in left subtree
     {
         // insert new TreeNode
         if (LeftNode == null)
         {
             LeftNode = new TreeNode <T>(insertValue);
         }
         else // continue traversing left subtree
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue.CompareTo(Data) > 0) // insert in right
     {
         // insert new TreeNode
         if (RightNode == null)
         {
             RightNode = new TreeNode <T>(insertValue);
         }
         else // continue traversing right subtree
         {
             RightNode.Insert(insertValue);
         }
     }
 }
Exemple #3
0
 public void Insert(int insertValue)
 {
     if (insertValue < Data)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(insertValue);
         }
         else
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue > Data)
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode(insertValue);
         }
         else
         {
             RightNode.Insert(insertValue);
         }
     }
 }
 public void Insert(Movie myMovie)
 {
     //Lexographically, if the new node is equal to or greater than the current node
     if (string.Compare(myMovie.Title, this.Title) == 0 || string.Compare(myMovie.Title, this.Title) == 1)
     {
         if (RightNode == null)
         {
             RightNode = myMovie;
         }
         else
         {
             RightNode.Insert(myMovie);
         }
     }
     else
     {
         if (LeftNode == null)
         {
             LeftNode = myMovie;
         }
         else
         {
             LeftNode.Insert(myMovie);
         }
     }
 }
Exemple #5
0
 public void Insert(IComparable insertValue)
 {
     if (insertValue.CompareTo(Data) < 0)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(insertValue);
         }
         else
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue.CompareTo(Data) > 0)
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode(insertValue);
         }
         else
         {
             RightNode.Insert(insertValue);
         }
     }
 }
        public void Insert(T data)
        {
            var compared = data.CompareTo(Element);

            if (compared < 0)
            {
                if (LeftNode != null)
                {
                    LeftNode.Insert(data);
                }
                else
                {
                    LeftNode = new Node <T>(data);
                }
            }
            else if (compared > 0)
            {
                if (RightNode != null)
                {
                    RightNode.Insert(data);
                }
                else
                {
                    RightNode = new Node <T>(data);
                }
            }
        }
Exemple #7
0
 public void Insert(MarkGeometryPoint point)
 {
     if (Value == null)
     {
         Value = point;
     }
     else if (IsLesser(Origin, point, Value))
     {
         if (LeftNode == null)
         {
             LeftNode = new IntersectionsBinaryTree(Origin, point);
         }
         else
         {
             LeftNode.Insert(point);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode = new IntersectionsBinaryTree(Origin, point);
         }
         else
         {
             RightNode.Insert(point);
         }
     }
 }
 public void Insert(D data)
 {
     if (data.CompareTo(Data) < 0)
     {
         if (null == LeftNode)
         {
             LeftNode = new Node <D>(data);
         }
         else
         {
             LeftNode.Insert(data);
         }
     }
     else
     {
         if (null == RightNode)
         {
             RightNode = new Node <D>(data);
         }
         else
         {
             RightNode.Insert(data);
         }
     }
 }
Exemple #9
0
        } // end constructor

        // insert TreeNode into Tree that contains nodes;
        // ignore duplicate values
        public void Insert(IComparable insertValue)
        {
            if (insertValue.CompareTo(Data) < 0) // insert in left subtree
            {
                // insert new TreeNode
                if (LeftNode == null)
                {
                    LeftNode = new TreeNode(insertValue);
                }
                else // continue traversing left subtree
                {
                    LeftNode.Insert(insertValue);
                }
            } // end if
            else if (insertValue.CompareTo(Data) > 0)  // insert in right
            {
                // insert new TreeNode
                if (RightNode == null)
                {
                    RightNode = new TreeNode(insertValue);
                }
                else // continue traversing right subtree
                {
                    RightNode.Insert(insertValue);
                }
            } // end else if
        }     // end method Insert
 public void Insert(int value)
 {
     //if the value passed is greater than or equal to the data then insert right node
     if (value >= Data)
     {
         //if rightNode is null, instantiate a new rightNode
         if (RightNode == null)
         {
             RightNode = new TreeNode(value);
         }
         //if not null, recursively call insert on the rightNode
         else
         {
             RightNode.Insert(value);
         }
     }
     else
     {
         //if the value passed is less than the data, insert left node
         //if leftNode is null, instantiate one
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(value);
         }
         //if not null, recursively call Insert on the leftNode
         else
         {
             LeftNode.Insert(value);
         }
     }
 }
Exemple #11
0
        protected void InternalInsertLeft(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool uncheckedValue)
        {
            switch (PropagateInsertLeft)
            {
            case PropagateAction.True:
                LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                break;

            case PropagateAction.Ensure:
            case PropagateAction.Ignore:
                using (Row leftRow = new Row(program.ValueManager, LeftNode.DataType.RowType))
                {
                    newRow.CopyTo(leftRow);
                    using (IRow currentRow = LeftNode.Select(program, leftRow))
                    {
                        if (currentRow != null)
                        {
                            if (PropagateInsertLeft == PropagateAction.Ensure)
                            {
                                LeftNode.Update(program, currentRow, newRow, valueFlags, false, uncheckedValue);
                            }
                        }
                        else
                        {
                            LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                        }
                    }
                }
                break;
            }
        }
        public void Insert(int value, INode <int> parentNode)
        {
            if (value == 0 || value == this.Value)
            {
                return;
            }

            if (value < this.Value)
            {
                if (LeftNode == null)
                {
                    LeftNode = new Node {
                        Value = value
                    };
                    this.ParentNode = parentNode;
                }
                else
                {
                    LeftNode.Insert(value, this);
                }
            }
            else
            {
                if (RightNode == null)
                {
                    RightNode = new Node {
                        Value = value
                    };
                    this.ParentNode = parentNode;
                }
                else
                {
                    RightNode.Insert(value, this);
                }
            }
        }
Exemple #13
0
        protected override void InternalExecuteUpdate(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool checkConcurrency, bool uncheckedValue)
        {
            if (PropagateUpdateLeft && PropagateUpdateRight && EnforcePredicate)
            {
                // Attempt to update the row in the left node
                try
                {
                    if (PropagateUpdateLeft)
                    {
                        using (IRow leftRow = LeftNode.FullSelect(program, oldRow))
                        {
                            if (leftRow != null)
                            {
                                LeftNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                            }
                        }

                        LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                    }
                }
                catch (DataphorException exception)
                {
                    if ((exception.Severity == ErrorSeverity.User) || (exception.Severity == ErrorSeverity.Application))
                    {
                        if (PropagateUpdateRight)
                        {
                            using (IRow rightRow = RightNode.FullSelect(program, oldRow))
                            {
                                if (rightRow != null)
                                {
                                    RightNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                                }
                            }

                            RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                        }
                        return;
                    }
                    throw;
                }

                // Attempt to update the row in the right node
                try
                {
                    if (PropagateUpdateRight)
                    {
                        using (IRow rightRow = RightNode.FullSelect(program, oldRow))
                        {
                            if (rightRow != null)
                            {
                                RightNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                            }
                        }

                        RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                    }
                }
                catch (DataphorException exception)
                {
                    if ((exception.Severity != ErrorSeverity.User) && (exception.Severity != ErrorSeverity.Application))
                    {
                        throw;
                    }
                }
            }
            else
            {
                if (PropagateUpdateLeft)
                {
                    LeftNode.Update(program, oldRow, newRow, valueFlags, checkConcurrency, uncheckedValue);
                }

                if (PropagateUpdateRight)
                {
                    RightNode.Update(program, oldRow, newRow, valueFlags, checkConcurrency, uncheckedValue);
                }
            }
        }