public BinaryTree <TValue> Insert(TValue value)
        {
            if (value.CompareTo(Value) >= 0)
            {
                if (RightNode == null)
                {
                    RightNode = new BinaryTree <TValue>(value);
                    return(this);
                }

                if (value.CompareTo(Value) == 0)
                {
                    var temp = new BinaryTree <TValue>(value)
                    {
                        RightNode = RightNode
                    };
                    RightNode = temp;
                    return(this);
                }

                RightNode.Insert(value);
                return(this);
            }

            if (LeftNode == null)
            {
                LeftNode = new BinaryTree <TValue>(value);
                return(this);
            }

            LeftNode.Insert(value);

            return(this);
        }
 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);
         }
     }
 }
Beispiel #3
0
        protected void ValidatePredicate(Program program, IRow row)
        {
            if (EnforcePredicate)
            {
                bool rightNodeValid = false;
                try
                {
                    RightNode.Insert(program, null, row, null, false);
                    rightNodeValid = true;
                    RightNode.Delete(program, row, false, false);
                }
                catch (DataphorException exception)
                {
                    if ((exception.Severity != ErrorSeverity.User) && (exception.Severity != ErrorSeverity.Application))
                    {
                        throw;
                    }
                }

                if (rightNodeValid)
                {
                    throw new RuntimeException(RuntimeException.Codes.RowViolatesDifferencePredicate, ErrorSeverity.User);
                }
            }
        }
Beispiel #4
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(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);
         }
     }
 }
Beispiel #6
0
        protected void InternalInsertRight(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool uncheckedValue)
        {
            switch (PropagateInsertRight)
            {
            case PropagateAction.True:
                RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                break;

            case PropagateAction.Ensure:
            case PropagateAction.Ignore:
                using (Row rightRow = new Row(program.ValueManager, RightNode.DataType.RowType))
                {
                    newRow.CopyTo(rightRow);
                    using (IRow currentRow = RightNode.Select(program, rightRow))
                    {
                        if (currentRow != null)
                        {
                            if (PropagateInsertRight == PropagateAction.Ensure)
                            {
                                RightNode.Update(program, currentRow, newRow, valueFlags, false, uncheckedValue);
                            }
                        }
                        else
                        {
                            RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                        }
                    }
                }
                break;
            }
        }
Beispiel #7
0
 //INSERT NODE
 public void Insert(IComparable insertValue)
 {
     if (insertValue.CompareTo(Data) < 0)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode <T>(insertValue);
         }
         else
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue.CompareTo(Data) > 0)
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode <T>(insertValue);
         }
         else
         {
             RightNode.Insert(insertValue);
         }
     }
 }
Beispiel #8
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);
                }
            }
        }