Ejemplo n.º 1
0
 internal void FireNodeOperation(IRBNode node, NodeOperation operation)
 {
     if (NodeOperation != null)
     {
         NodeOperation(node, operation);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Walk the logical tree, and perform an operation on all nodes and children of nodes.
        /// This is slightly more complex than it might otherwise be because it makes no assumptions
        /// that the Logical Tree is strongly typed. It is the responsibility of the operation to make sure
        /// that it can handle the node it receives.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="operation"></param>
        private void WalkLogicalTree(object node, NodeOperation operation)
        {
            if (node != null)
            {
                operation(node);
            }

            DependencyObject treeNode = node as DependencyObject;

            if (treeNode == null)
            {
                return;
            }

            IEnumerator e = LogicalTreeHelper.GetChildren(treeNode).GetEnumerator();

            if (e == null)
            {
                return;
            }

            while (e.MoveNext())
            {
                WalkLogicalTree(e.Current, operation);
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldHandleIndexDropConcurrentlyWithOperation(NodeOperation operation) throws Throwable
        private void ShouldHandleIndexDropConcurrentlyWithOperation(NodeOperation operation)
        {
            // given
            long[]          nodes           = CreateNodes();
            IndexDefinition indexDefinition = CreateIndex();

            // when
            Race race = new Race();

            race.AddContestant(() =>
            {
                using (Transaction tx = Db.beginTx())
                {
                    indexDefinition.Drop();
                    tx.Success();
                }
            }, 1);
            for (int i = 0; i < NODES; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long nodeId = nodes[i];
                long nodeId = nodes[i];
                race.AddContestant(throwing(() =>
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        operation.Run(nodeId);
                        tx.Success();
                    }
                }));
            }

            // then
            race.Go();
        }
Ejemplo n.º 4
0
 public NodeOperationDetails(NodeOperation operation, INode map, Node node)
 {
     Operation = operation;
     Map = map;
     Nodes = new [] {node};
     OldLocation = node.Location;
 }
 internal NodeDictionary(int index, bool hasMine, int mineCount, NodeOperation op)
 {
     Index     = index;
     HasMine   = hasMine;
     MineCount = (byte)mineCount;
     State     = _operationToStateMap[op];
 }
Ejemplo n.º 6
0
 public NodeOperationDetails(NodeOperation operation, INode map, Node node)
 {
     Operation   = operation;
     Map         = map;
     Nodes       = new [] { node };
     OldLocation = node.Location;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// it is maintaind the current operation type is remove and newOp operation type is insert
 /// </summary>
 /// <param name="current"></param>
 /// <param name="currentB"></param>
 /// <param name="newOp"></param>
 /// <returns></returns>
 private bool InsertOnRemoveHandler(ref NodeOperation current, ref NodeOperation currentB, NodeOperation newOp)
 {
     if (currentB == null)       // insert done on remove, change it to set
     {
         if (current.Count == 1) // if there is only one remove
         {
             current.Operation = OperationType.Set;
             current.Value     = newOp.Value;
         }
         else
         {
             current.Count--;                          //decrease the remove count
             currentB           = new NodeOperation(); // and append a new set opertaion
             currentB.Operation = OperationType.Set;
             currentB.Value     = newOp.Value;
         }
         return(true);    // the insert operation is assimilated into the node
     }
     //the only options here is that currentB operation type is set  (other operationB are not allowed, it always remove and set
     if (currentB.Operation != OperationType.Set)
     {
         throw new Exception();
     }
     return(false); // the insert should push this right and continue
 }
Ejemplo n.º 8
0
        /*####################################################################*/
        /*                           DFS Operations                           */
        /*####################################################################*/

        public void DfsOperationChildren(NodeOperation <T> operation)
        {
            foreach (var child in Children)
            {
                child.DfsOperation(operation);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// handles appending of a remove operation to the node
 /// </summary>
 /// <param name="current"></param>
 /// <param name="currentB"></param>
 /// <param name="newOp"></param>
 /// <returns></returns>
 private bool RemoveHandler(ref NodeOperation current, ref NodeOperation currentB, NodeOperation newOp)
 {
     if (current == null)    // this is no operation node , push it right and continue
     {
         current = newOp;
         return(true);  // the remove operation is assimilated into the node
     }
     if (current.Operation == OperationType.Insert)
     {
         if (newOp.Count != 1)
         {
             throw new InvalidOperationException();
         }
         current  = null; // this is a noop , insert and then remove at the same index
         currentB = null;
         return(true);    // the remove operation is assimilated into the node
     }
     if (current.Operation == OperationType.Set)
     {
         if (newOp.Count != 1)
         {
             throw new InvalidOperationException();
         }
         // setting a value and the removeing that index , it should be overriden
         current = newOp;
         return(true); // the remove operation is assimilated into the node
     }
     //current operation is remove.
     currentB = null; // regardles of the value of currentB , the set operation that it might contain is removed
                      //no addiational operations just add one to the remove count
     current.Count += newOp.Count;
     return(true);    // the remove operation is assimilated into the node
 }
Ejemplo n.º 10
0
 /// <summary>
 /// handles appending of a set operation to the node
 /// </summary>
 /// <param name="current"></param>
 /// <param name="currentB"></param>
 /// <param name="newOp"></param>
 /// <returns></returns>
 private bool SetHandler(ref NodeOperation current, ref NodeOperation currentB, NodeOperation newOp)
 {
     if (current == null)    // this is no operation node , apply the set operation
     {
         current = newOp;
         return(true);                                                                        // the set operation is assimilated into the node
     }
     if (current.Operation == OperationType.Insert || current.Operation == OperationType.Set) // this means currentB is false (because it is only allowed when current is remove and currentb is set
     {
         current.Value = newOp.Value;                                                         // just use the new value instead
         return(true);
     }
     //current operation is remove
     if (currentB == null)    // this should be removeSet node then , if there is no set it is created
     {
         currentB = newOp;
     }
     else
     {
         if (currentB.Operation != OperationType.Set)
         {
             throw new InvalidOperationException();
         }
         currentB.Value = newOp.Value;
     }
     return(true); // the set operation is assimilated into the node
 }
Ejemplo n.º 11
0
 internal BenchmarkNodeWithoutIn(BenchmarkNodeWithoutIn node, NodeOperation op)
 {
     Index     = node.Index;
     HasMine   = node.HasMine;
     MineCount = node.MineCount;
     State     = _operationToStateMap[op];
 }
Ejemplo n.º 12
0
        public void TestMultipleAdd()
        {
            double a    = 5.0;
            INode  tree = new NodeOperation(new NodeOperation(new NodeValue(a), new NodeValue(a), OperationType.ADDITION), new NodeOperation(new NodeValue(a), new NodeValue(a), OperationType.ADDITION), OperationType.ADDITION);

            Assert.AreEqual(20.0, tree.GetResult(), 0.001, "Tripple add doesn't work");
        }
Ejemplo n.º 13
0
        public Turn(int nodeIndex, NodeOperation operation)
        {
            Debug.Assert(nodeIndex >= 0);
            Debug.Assert(Enum.IsDefined(operation));

            NodeIndex = nodeIndex;
            Operation = operation;
        }
Ejemplo n.º 14
0
        public void TestSub()
        {
            double a    = 5.0;
            double b    = 3.5;
            INode  tree = new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.SUBSTRACTION);

            Assert.AreEqual(1.5, tree.GetResult(), 0.001, "Subtraction does not work.");
        }
Ejemplo n.º 15
0
        public void TestMul()
        {
            double a    = 5.0;
            double b    = 2.0;
            INode  tree = new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.MULTIPLICATION);

            Assert.AreEqual(10, tree.GetResult(), 0.001, "Multiply does not work.");
        }
Ejemplo n.º 16
0
        public void TestAdd()
        {
            double a    = 5.0;
            double b    = 3.5;
            INode  tree = new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.ADDITION);

            Assert.AreEqual(8.5, tree.GetResult(), 0.001, "Add does not work.");
        }
Ejemplo n.º 17
0
        public void TestMultipleSub()
        {
            double a    = 20.0;
            double b    = 5.0;
            INode  tree = new NodeOperation(new NodeValue(a), new NodeOperation(new NodeValue(b), new NodeValue(b), OperationType.ADDITION), OperationType.SUBSTRACTION);

            Assert.AreEqual(10, tree.GetResult(), 0.001, "Something went wrong.");
        }
Ejemplo n.º 18
0
 public void Commit()
 {
     NodeOperation.Commit();
     foreach (var edgeEdit in EdgeOperations)
     {
         edgeEdit.Commit();
     }
 }
Ejemplo n.º 19
0
        public void TestMultipleSub_Mul()
        {
            double a = 10.0;
            double b = 2.0;

            INode tree = new NodeOperation(new NodeValue(a), new NodeOperation(new NodeValue(b), new NodeValue(b), OperationType.MULTIPLICATION), OperationType.SUBSTRACTION);

            Assert.AreEqual(6.0, tree.GetResult(), 0.001, "Multiple multiplication + substraction doesn't work");
        }
Ejemplo n.º 20
0
        public void TestMultipleSub_Div()
        {
            double a = 10.0;
            double b = 5.0;

            INode tree = new NodeOperation(new NodeValue(a), new NodeOperation(new NodeValue(b), new NodeValue(b), OperationType.DIVISION), OperationType.SUBSTRACTION);

            Assert.AreEqual(9.0, tree.GetResult(), 0.001, "Multiple division + substraction doesn't work");
        }
Ejemplo n.º 21
0
        public void TestMultipleAdd_Div_zero()
        {
            double a = 0;
            double b = 5;

            INode tree = new NodeOperation(new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.DIVISION), new NodeValue(b), OperationType.ADDITION);

            Assert.AreEqual(5.0, tree.GetResult(), 0.001, "Multiple addition + division with zero doesn't work");
        }
Ejemplo n.º 22
0
        public void TestPower()
        {
            double a = 5;
            double b = 2;

            INode tree = new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.POWER);

            Assert.AreEqual(25.0, tree.GetResult(), 0.001, "Multiple addition + division with zero doesn't work");
        }
Ejemplo n.º 23
0
        public void TestMultipleAdd_Mul()
        {
            double a = 5.0;
            double b = 2.0;

            INode tree = new NodeOperation(new NodeValue(a), new NodeOperation(new NodeValue(b), new NodeValue(b), OperationType.MULTIPLICATION), OperationType.ADDITION);

            Assert.AreEqual(9.0, tree.GetResult(), 0.001, "Multiple multiplication + addition doesn't work");
        }
Ejemplo n.º 24
0
        public void TestMultipleAdd_Div()
        {
            double a = 5.0;
            double b = 6.0;
            double c = 3.0;

            INode tree = new NodeOperation(new NodeValue(a), new NodeOperation(new NodeValue(b), new NodeValue(c), OperationType.DIVISION), OperationType.ADDITION);

            Assert.AreEqual(7.0, tree.GetResult(), 0.001, "Multiple division + addition doesn't work");
        }
Ejemplo n.º 25
0
 public void DeleteWith(Node n)
 {
     Key = n.Key;
     if (n.KeyModifier != 0 || KeyModifier != 0)
     {
         throw new InvalidOperationException();
     }
     mOperationA = n.mOperationA;
     mOperationB = n.mOperationB;
 }
Ejemplo n.º 26
0
        public void TestMultipleDiv()
        {
            double        a    = 100.0;
            double        b    = 2.0;
            double        c    = 5.0;
            NodeOperation p1   = new NodeOperation(new NodeValue(a), new NodeValue(b), OperationType.DIVISION);
            NodeOperation p2   = new NodeOperation(new NodeValue(p1.GetResult()), new NodeValue(b), OperationType.DIVISION);
            INode         tree = new NodeOperation(new NodeValue(p2.GetResult()), new NodeValue(c), OperationType.DIVISION);

            Assert.AreEqual(5.0, tree.GetResult(), 0.001, "Multiple division doesn't work");
        }
Ejemplo n.º 27
0
        public void TestMultipleMul()
        {
            double a = 2.0;
            double b = 3.0;

            NodeOperation p1   = new NodeOperation(new NodeValue(a), new NodeValue(a), OperationType.MULTIPLICATION);
            NodeOperation p2   = new NodeOperation(new NodeValue(p1.GetResult()), new NodeValue(b), OperationType.MULTIPLICATION);
            INode         tree = new NodeOperation(new NodeValue(p2.GetResult()), new NodeValue(b), OperationType.MULTIPLICATION);

            Assert.AreEqual(36.0, tree.GetResult(), 0.001, "Multiple multiplication doesn't work");
        }
Ejemplo n.º 28
0
        public NodeOperationDetails(NodeOperation operation, INode map, IEnumerable<Node> nodes, IEnumerable<Relationship> relationships)
        {
            Operation = operation;
            Map = map;
            Nodes = nodes;
            Relationships = relationships;

            if (OldLocation == null)
            {
                OldLocation = Nodes.Select(q => q.Location).OrderBy(q => q.X).ThenBy(q => q.Y).FirstOrDefault();
            }
        }
Ejemplo n.º 29
0
        public NodeOperationDetails(NodeOperation operation, INode map, IEnumerable <Node> nodes, IEnumerable <Relationship> relationships)
        {
            Operation     = operation;
            Map           = map;
            Nodes         = nodes;
            Relationships = relationships;

            if (OldLocation == null)
            {
                OldLocation = Nodes.Select(q => q.Location).OrderBy(q => q.X).ThenBy(q => q.Y).FirstOrDefault();
            }
        }
Ejemplo n.º 30
0
 public Node(int key, T value, Node left, Node right, Node parent, NodeColor color, OperationType op)
 {
     Key                   = key;
     Parent                = parent;
     Left                  = left;
     Right                 = right;
     Color                 = color;
     mOperationA           = new NodeOperation();
     mOperationA.Count     = 1;
     mOperationA.Operation = op;
     mOperationA.Value     = value;
 }
 internal NodeSwitch(int index, bool hasMine, int mineCount, NodeOperation op)
 {
     Index     = index;
     HasMine   = hasMine;
     MineCount = (byte)mineCount;
     State     = op switch
     {
         NodeOperation.Reveal => NodeState.Revealed,
         NodeOperation.Flag => NodeState.Flagged,
         _ => NodeState.Hidden,
     };
 }
Ejemplo n.º 32
0
 /// <summary>
 /// handles appending of an insert operation to the node
 /// </summary>
 /// <param name="current"></param>
 /// <param name="currentB"></param>
 /// <param name="newOp"></param>
 /// <returns></returns>
 private bool InsertHandler(ref NodeOperation current, ref NodeOperation currentB, NodeOperation newOp)
 {
     if (current == null)    // this is no operation node , push it right and continue
     {
         return(false);
     }
     if (current.Operation == OperationType.Remove)
     {
         return(InsertOnRemoveHandler(ref current, ref currentB, newOp));
     }
     return(false); // both insert and set require pushing this node right and continuing with insertion
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Walk the logical tree, and perform an operation on all nodes and children of nodes.
        /// This is slightly more complex than it might otherwise be because it makes no assumptions 
        /// that the Logical Tree is strongly typed. It is the responsibility of the operation to make sure
        /// that it can handle the node it receives. 
        /// </summary> 
        /// <param name="node"></param>
        /// <param name="operation"></param> 
        private void WalkLogicalTree(object node, NodeOperation operation)
        {
            if (node != null)
            { 
                operation(node);
            } 
 
            DependencyObject treeNode = node as DependencyObject;
            if (treeNode == null) 
            {
                return;
            }
 
            IEnumerator e = LogicalTreeHelper.GetChildren(treeNode).GetEnumerator();
            if (e == null) 
            { 
                return;
            } 

            while (e.MoveNext())
            {
                WalkLogicalTree(e.Current, operation); 
            }
        }