Beispiel #1
0
        public void AddRage_MultipleElements_ShouldSortWhenTravers()
        {
            var st = new SortedTree<int>();
            st.AddRange(new List<int> { 3, 23, 52, 1, 44, 11, 9 });

            CollectionAssert.AreEqual(new List<int> { 1,3,9,11,23,44,52 }, st.Traverse());
        }
Beispiel #2
0
 public virtual bool Add(SortedTree <T> child)
 {
     if (child.Value.Equals(this.Value))
     {
         return(false);
     }
     else if (child.Value.CompareTo(this.Value) < 0)
     {
         if (this.Left == null)
         {
             this.Left    = child;
             child.Parent = this;
             return(true);
         }
         else
         {
             return(this.Left.Add(child));
         }
     }
     else
     {
         if (this.Right == null)
         {
             this.Right   = child;
             child.Parent = this;
             return(true);
         }
         else
         {
             return(this.Right.Add(child));
         }
     }
 }
Beispiel #3
0
            /// <summary>
            /// Commits the edits to the current archive file and disposes of this class.
            /// </summary>
            public override void Commit()
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                GetKeyRange(m_sortedTreeFile.m_firstKey, m_sortedTreeFile.m_lastKey);

                if (m_tree != null)
                {
                    m_tree.Flush();
                    m_tree = null;
                }
                if (m_binaryStream1 != null)
                {
                    m_binaryStream1.Dispose();
                    m_binaryStream1 = null;
                }
                if (m_subStream != null)
                {
                    m_subStream.Dispose();
                    m_subStream = null;
                }

                m_currentTransaction.CommitAndDispose();
                InternalDispose();
            }
Beispiel #4
0
        public void Add_OneElement_ShouldReturnWhenTravers()
        {
            var st = new SortedTree<int>();
            st.Add(3);

            CollectionAssert.AreEqual(new List<int> { 3 }, st.Traverse());
        }
        private void CreateArchiveFile <TKey, TValue>(SubFileName fileName, EncodingDefinition storageMethod, int maxSortedTreeBlockSize)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            if (maxSortedTreeBlockSize < 1024)
            {
                throw new ArgumentOutOfRangeException(nameof(maxSortedTreeBlockSize), "Must be greater than 1024");
            }
            if ((object)storageMethod == null)
            {
                throw new ArgumentNullException("storageMethod");
            }

            using (TransactionalEdit trans = m_fileStructure.BeginEdit())
            {
                using (SubFileStream fs = trans.CreateFile(fileName))
                    using (BinaryStream bs = new BinaryStream(fs))
                    {
                        int blockSize = m_fileStructure.Snapshot.Header.DataBlockSize;

                        while (blockSize > maxSortedTreeBlockSize)
                        {
                            blockSize >>= 2;
                        }

                        SortedTree <TKey, TValue> tree = SortedTree <TKey, TValue> .Create(bs, blockSize, storageMethod);

                        tree.Flush();
                    }
                trans.ArchiveType = FileType;
                trans.CommitAndDispose();
            }
        }
Beispiel #6
0
        private static void AreEqualToStringAfterCloneHelper(SortedTree <ClassAsTreeValue <string> > tree, string comment)
        {
            string expected = tree.ToString();
            string actual   = ((SortedTree <ClassAsTreeValue <string> >)(((ICloneable)tree).Clone())).ToString();

            Assert.AreEqual(expected, actual, "ToString mismatch; " + comment);
        }
Beispiel #7
0
    public bool Remove(T element)
    {
        bool isRemoved;

        if (this.tree.Value.Equals(element) && this.tree.Left == null && this.tree.Right == null)
        {
            this.tree = null;
            isRemoved = true;
        }
        else
        {
            isRemoved = this.tree.Remove(element);

            if (this.tree.Value.Equals(element))
            {
                if (this.tree.Right != null)
                {
                    this.tree = this.tree.Right;
                }
                else if (this.tree.Left != null)
                {
                    this.tree = this.tree.Left;
                }
            }
        }

        if (isRemoved)
        {
            this.Count--;
        }
        return(isRemoved);
    }
Beispiel #8
0
        public void TestConnectTheNodeToOtherNode_Test2_RootTest()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEB", tree, "after initialization");
            Assert.AreEqual(2, tree.GetRoots().Count, "there should be 2 roots");
            tree.AddNode(L);
            AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBL", tree, "after L adding");
            Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots");
            tree.AddNode(M);
            AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBLM", tree, "after M adding");
            Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots");
            tree.ConnectTheNodeToOtherNode(L, 0, M, 0);
            Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots");
            AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBML", tree, "after connecting L and M");
            tree.AddNode(N);
            Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots");
            AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBMLN", tree, "after N adding");
            tree.ConnectTheNodeToOtherNode(J, 0, L, 0);
            Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots");
            AreEqualGetFroeachRepresentationHelper("CFMLJGDAKHIEBN", tree, "after connecting J and L");
        }
Beispiel #9
0
        public void TestHeight()
        {
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            Assert.AreEqual(5, tree.Height, "Wrong Height of the tree");
        }
Beispiel #10
0
        public void TestGetNodesFromLevel()
        {
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);

            string expected = "";

            GetNodesFromLevelHelper(tree, expected, 0);

            expected = "CFJI";
            GetNodesFromLevelHelper(tree, expected, 1);

            expected = "GH";
            GetNodesFromLevelHelper(tree, expected, 2);

            expected = "DE";
            GetNodesFromLevelHelper(tree, expected, 3);

            expected = "AB";
            GetNodesFromLevelHelper(tree, expected, 4);

            expected = "K";
            GetNodesFromLevelHelper(tree, expected, 5);
        }
Beispiel #11
0
        public void TestMoveNodeToRoots()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            tree.MoveNodeToRoots(G);
            string expected;
            string actual;

            expected = "CFDAKJHIEBG";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");
            tree.MoveNodeToRoots(J);
            expected = "CFDAKHIEBGJ";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");
        }
Beispiel #12
0
        public void TestCount()
        {
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            Assert.AreEqual(11, tree.Count, "Wrong count of elements");
        }
Beispiel #13
0
        public void TestTestTreeIfCanBeConnected()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            SortedTree <ClassAsTreeValue <string> > tree2 = tree.GetSubtreeFromNode(B);

            tree2.RemoveValue(J, false);
            bool result;

            result = tree.TestTreeIfCanBeConnected(J, 0, tree2, 0);
            Assert.AreEqual(false, result, "This trees cannot be connected");
            tree.RemoveValue(B, false);
            result = tree.TestTreeIfCanBeConnected(J, 0, tree2, 0);
            Assert.AreEqual(true, result, "This trees can be connected");
        }
Beispiel #14
0
 /// <summary>
 ///A test for GetNode
 ///</summary>
 public void GetNodeTestHelper(ref SortedTree <ClassAsTreeValue <string> > tree)
 {
     AddNodeTestHelper(ref tree);
     SortedTree <ClassAsTreeValue <string> > .SortedTreeNode node = tree.GetNode(A);
     Assert.IsTrue(node != null, "there should be one (A) element on the tree");
     Assert.AreEqual(node.Value, A);
 }
Beispiel #15
0
        public void BenchmarkOld(int pointCount)
        {
            SortedPointBuffer <HistorianKey, HistorianValue> points = new SortedPointBuffer <HistorianKey, HistorianValue>(pointCount, true);

            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            for (int x = 0; x < pointCount; x++)
            {
                key.PointID = (ulong)x;
                points.TryEnqueue(key, value);
            }

            points.IsReadingMode = true;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (BinaryStream bs = new BinaryStream(true))
            {
                SortedTree <HistorianKey, HistorianValue> st = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096, HistorianFileEncodingDefinition.TypeGuid);

                st.TryAddRange(points);
                //SequentialSortedTreeWriter<HistorianKey, HistorianValue>.Create(bs, 4096, SortedTree.FixedSizeNode, points);
            }
            sw.Stop();

            System.Console.WriteLine("Points {0}: {1}MPPS", pointCount, (pointCount / sw.Elapsed.TotalSeconds / 1000000).ToString("0.0"));
        }
Beispiel #16
0
 /// <summary>
 /// Helper that create the example tree.
 /// </summary>
 /// <param name="tree">The tree.</param>
 private void AddNodeWholeTreeTestHelper(ref SortedTree <ClassAsTreeValue <string> > tree)
 {
     //K
     //|
     //A     B
     //|\     \
     //C D     E
     // / \   / \
     // F  G  H  I
     //     \/
     //     J
     SortedTree <ClassAsTreeValue <string> > .SortedTreeNode node;
     SortedTree <ClassAsTreeValue <string> > .SortedTreeNode parentnode;
     SortedTree <ClassAsTreeValue <string> > .SortedTreeNode parentnode2;
     node = tree.AddNode(K);
     Assert.AreEqual(node.Value, K, "Element that is added must be equal to oryginal element");
     Assert.AreEqual(0, node.ParentNodesCount, "Parrent Node for root element must be null");
     parentnode = node;
     node       = tree.AddNode(K, 0, A, 0);
     Assert.AreEqual(node.Value, A, "Element that is added must be equal to original element");
     Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(K)), parentnode, "Parent Node for A element must be K");
     parentnode = node;
     node       = tree.AddNode(A, 0, C, 0);
     Assert.AreEqual(node.Value, C, "Element that is added must be equal to original element");
     Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(A)), parentnode, "Parent Node for C element must be A");
     node = tree.AddNode(A, 1, D, 0);
     Assert.AreEqual(node.Value, D, "Element that is added must be equal to original element");
     Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(A)), parentnode, "Parent Node for D element must be A");
     parentnode2 = node; //D is saved here
     parentnode  = null;
     node        = tree.AddNode(null, 0, B, 0);
     Assert.AreEqual(B, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(0, node.ParentNodesCount, "Parent Node for root element must be null");
     parentnode = node;
     node       = tree.AddNode(B, 0, E, 0);
     Assert.AreEqual(node.Value, E, "Element that is added must be equal to original element");
     Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(B)), parentnode, "Parent Node for E element must be B");
     parentnode = node;// save E;
     node       = tree.AddNode(D, 0, F, 0);
     Assert.AreEqual(F, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(D)), "Parent Node for F element must be D");
     node = tree.AddNode(D, 1, G, 1);
     Assert.AreEqual(G, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(D)), "Parent Node for G element must be D");
     parentnode2 = node; //save G
     node        = tree.AddNode(E, 1, I, 0);
     Assert.AreEqual(I, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(E)), "Parent Node for I element must be E");
     node = tree.AddNode(E, 0, H, 0);
     Assert.AreEqual(H, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(E)), "Parent Node for H element must be E");
     parentnode = node;//save H
     node       = tree.AddNode(G, 0, J, 0);
     Assert.AreEqual(J, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(G)), "Parent Node for J element must be G");
     node = tree.AddNode(H, 0, J, 1);
     Assert.AreEqual(J, node.Value, "Element that is added must be equal to original element");
     Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(H)), "Parent Node for J element must be H");
 }
Beispiel #17
0
        private static void AreEqualGetFroeachRepresentationHelper(string expected, SortedTree <ClassAsTreeValue <string> > tree, string comment)
        {
            AreEqualToStringAfterCloneHelper(tree, comment);
            string actual;

            actual = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Foreach mismatch; " + comment);
        }
Beispiel #18
0
        public bool Remove(T element)
        {
            if (this.Value.Equals(element))
            {
                SortedTree <T> nextNode = null;
                if (this.Left == null && this.Right == null && this.Parent == null)
                {
                    throw new InvalidOperationException("Last sorted tree node can't be deleted");
                }
                else if (this.Left == null && this.Right == null)
                {
                    nextNode = null;
                }
                else if (this.Left != null && this.Right == null)
                {
                    nextNode = this.Left;
                }
                else
                {
                    nextNode = this.Right;
                    if (this.Left != null)
                    {
                        this.Right.Add(this.Left);
                    }
                }

                if (this.Parent != null && this.Value.CompareTo(this.Parent.Value) < 0)
                {
                    this.Parent.Left = nextNode;
                }
                else if (this.Parent != null)
                {
                    this.Parent.Right = nextNode;
                }

                if (nextNode != null)
                {
                    nextNode.Parent = this.Parent;
                }

                return(true);
            }
            else
            {
                if (this.Left != null && element.CompareTo(this.Value) < 0)
                {
                    return(this.Left.Remove(element));
                }
                else if (this.Right != null && element.CompareTo(this.Value) > 0)
                {
                    return(this.Right.Remove(element));
                }
            }

            return(false);
        }
Beispiel #19
0
        private static void GetNodesFromLevelHelper(SortedTree <ClassAsTreeValue <string> > tree, string expected, int level)
        {
            string actual = "";

            foreach (SortedTree <ClassAsTreeValue <string> > .SortedTreeNode value in tree.GetNodesFromLevel(level))
            {
                actual += value.Value.ToString();
            }
            Assert.AreEqual(expected, actual, "Problem with GetNodesFromLevel level:" + level.ToString());
        }
Beispiel #20
0
        public void Remove_AddThreeElementsRemoveOne_ShouldRemoveElement()
        {
            var st = new SortedTree<int>(true);
            st.Add(2);
            st.Add(4);
            st.Add(1);
            st.Remove(1);

            CollectionAssert.AreEqual(new List<int> { 2,4 }, st.Traverse());
        }
Beispiel #21
0
        private static string GetForeachRepresentation(SortedTree <ClassAsTreeValue <string> > tree)
        {
            string actual = "";

            foreach (ClassAsTreeValue <string> values in tree)
            {
                actual += values.m_value;
            }
            return(actual);
        }
Beispiel #22
0
            internal Editor(SortedTreeTable <TKey, TValue> sortedTreeFile)
            {
                m_sortedTreeFile     = sortedTreeFile;
                m_currentTransaction = m_sortedTreeFile.m_fileStructure.BeginEdit();
                m_subStream          = m_currentTransaction.OpenFile(sortedTreeFile.m_fileName);
                m_binaryStream1      = new BinaryStream(m_subStream);
                m_tree = SortedTree <TKey, TValue> .Open(m_binaryStream1);

                m_tree.AutoFlush = false;
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="OPCClientTransaction"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="ParentDataQueue">The parent data queue.</param>
 internal OPCClientTransaction( OPCCliConfiguration.TransactionsRow configuration, OPCDataQueue ParentDataQueue )
   : base( ParentDataQueue, new TimeSpan( 0, 0, 0, 0, configuration.TransactionRate == 0 ? 1 : configuration.TransactionRate ) )
 {
   bool canBeAdded = true;
   if ( !configuration.IsBadQualityValueNull() )
     m_BadQualityValue = configuration.BadQualityValue;
   m_StopIfBadQuality = configuration.StopIfBadQuality;
   OPCCliConfiguration.OperationsRow[] operations = configuration.GetOperationsRows();
   // stworzymy tablice operacji do wykonania;
   SortedList<long, Operation> operationList = new SortedList<long, Operation>( configuration.GetOperationsRows().Length );
   SortedList<long, OPCCliConfiguration.OperationsRow> operationRowList =
     new SortedList<long, OPCCliConfiguration.OperationsRow>( configuration.GetOperationsRows().Length );
   SortedTree<Operation> myOperationTree = new SortedTree<Operation>();
   try
   {
     //najpierw dodajemy wszystkie operacje
     foreach ( OPCCliConfiguration.OperationsRow row in configuration.GetOperationsRows() )
     {
       try
       {
         Operation operrowOperation = OperationFactory.GetOperation( row, m_StopIfBadQuality, m_BadQualityValue );
         operationRowList.Add( (long)operrowOperation.Statistics.Identifier, row );
         operationList.Add( (long)operrowOperation.Statistics.Identifier, operrowOperation );
         myOperationTree.AddNode( operrowOperation ); //najpiewr dodajemy wszystykie jako rooty
       }
       catch ( Exception ex )
       {
         Exception newExcetion = new Exception( String.Format( Resources.tx_OPCDataQueue_Operation_CannotBeAdded, row.Name ), ex );
         throw newExcetion;
       }
     }
     //teraz dodajemy wszystkie linki:
     foreach ( Operation node in myOperationTree )
       foreach ( OPCCliConfiguration.OperationLinksRow OpLinksRow in operationRowList[ node.Statistics.Identifier ].GetOperationLinksRowsByFK_OPERATION_OperationLinks() )
       {
         myOperationTree.ConnectTheNodeToOtherNode( operationList[ OpLinksRow.ID_Operation ], OpLinksRow.Input_number,
           operationList[ OpLinksRow.IDChild_Operation ], OpLinksRow.ChildOutput_number );
       }
   }
   catch ( Exception ex )
   {
     Main.MainComponent.SystemExceptionHandler( ex, 158, this.ToString() );
     canBeAdded = false;
   }
   if ( canBeAdded )
   {
     m_Transaction = new Transaction( configuration, myOperationTree );
     m_AllTransactions.Add( this );
   }
   else
   {
     Main.MainComponent.Tracer.TraceWarning( 194, this.GetType().ToString(),
       String.Format( Resources.tx_OPCDataQueue_Transaction_CannotBeAdded, configuration.Name ) );
   }
 }
Beispiel #24
0
        public void TestForeach()
        {
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);

            string expected = "CFJGDAKHIEB";
            string actual   = GetForeachRepresentation(tree);

            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            var tree           = new SortedTree <int>();
            var treeController = new SortedTreeController <int>(tree);

            tree = treeController.Insert(55);
            tree = treeController.Insert(57);
            tree = treeController.Insert(52);
            tree = treeController.Insert(0);
            tree = treeController.Insert(61);
        }
Beispiel #26
0
        public void TestToString()
        {
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);

            string expected = "UAOOI.ProcessObserver.RealTime.Utils.Collections.Generic.SortedTree`1[CAS.RealTime.UnitTests.SortedTreeTest+ClassAsTreeValue`1[System.String]] elements:{(K(Height:5)[0:(A(Height:4)[0:(C(Height:1)[]1:(D(Height:3)[0:(F(Height:1)[]1:(G(Height:2)[0:(J(Height:1)[]]]]](B(Height:4)[0:(E(Height:3)[0:(H(Height:2)[0:(J(Height:1)[]]1:(I(Height:1)[]]]}";
            string actual   = tree.ToString();

            Assert.AreEqual(expected, actual, "Wrong string representation");
        }
Beispiel #27
0
        public void CleanRedundantDependencies_SingleRedundancy_RedundanciesCleared()
        {
            var          rng              = new Random();
            const string innerDependency  = "mostUsedDependency";
            const string outterDependency = "redundant";
            var          entries          = new List <TestSortable>
            {
                new TestSortable(innerDependency),
                new TestSortable(outterDependency, innerDependency),
                new TestSortable("commonEntry1", innerDependency),
                new TestSortable("commonEntry2", innerDependency, outterDependency),
                new TestSortable("commonEntry3", innerDependency, outterDependency),
                new TestSortable("commonEntry4"),
                new TestSortable("commonEntry5", innerDependency, outterDependency),
                new TestSortable("commonEntry6", innerDependency, outterDependency),
                new TestSortable("commonEntry7", innerDependency),
            };
            int originalCount = entries.Count;
            var tree          = new SortedTree <string, TestSortable>();

            // Add entries in random order
            while (entries.Count > 0)
            {
                int rngSelected = rng.Next(0, entries.Count);
                Assert.IsTrue(tree.AddSorted(entries[rngSelected]));
                entries.RemoveAt(rngSelected);
            }

            Assert.AreEqual(originalCount, tree.Count);

            tree.CleanRedundantDependencies();

            Assert.AreEqual(originalCount, tree.Count);
            Assert.AreEqual(4, tree.DependencyUsedBy(outterDependency));
            Assert.AreEqual(3, tree.DependencyUsedBy(innerDependency));

            Assert.IsTrue(tree[outterDependency].Dependencies.Contains(innerDependency));

            Assert.IsTrue(tree["commonEntry1"].Dependencies.Contains(innerDependency));
            Assert.IsTrue(tree["commonEntry2"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry3"].Dependencies.Contains(outterDependency));

            Assert.IsTrue(tree["commonEntry5"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry6"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry7"].Dependencies.Contains(innerDependency));

            Assert.IsFalse(tree["commonEntry2"].Dependencies.Contains(innerDependency));
            Assert.IsFalse(tree["commonEntry3"].Dependencies.Contains(innerDependency));

            Assert.IsFalse(tree["commonEntry5"].Dependencies.Contains(innerDependency));
            Assert.IsFalse(tree["commonEntry6"].Dependencies.Contains(innerDependency));
        }
        private TestResults TestRandomBinaryStream(int pageSize, uint count)
        {
            //StringBuilder sb = new StringBuilder();
            Random         R     = new Random(1);
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            DiskIoSession.ReadCount     = 0;
            DiskIoSession.WriteCount    = 0;
            Stats.ChecksumCount         = 0;
            DiskIoSession.Lookups       = 0;
            DiskIoSession.CachedLookups = 0;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (BinaryStream bs = new BinaryStream(allocatesOwnMemory: true))
            {
                var table = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096);

                for (ulong x = 0; x < count; x++)
                {
                    key.Timestamp = (uint)R.Next();
                    key.PointID   = 2 * x;
                    value.Value3  = 3 * x;
                    value.Value1  = 4 * x;
                    //if ((x % 100) == 0)
                    //    sb.AppendLine(x + "," + DiskIoSession.ReadCount + "," + DiskIoSession.WriteCount);
                    //if (x == 1000)
                    //    DiskIoSession.BreakOnIO = true;
                    table.TryAdd(key, value);
                    //edit.AddPoint(uint.MaxValue - x, 2 * x, 3 * x, 4 * x);
                }
            }

            sw.Stop();

            //File.WriteAllText(@"C:\temp\" + pageSize + ".csv",sb.ToString());


            return(new TestResults()
            {
                PageSize = pageSize,
                Rate = (float)(count / sw.Elapsed.TotalSeconds / 1000000),
                ReadCount = DiskIoSession.ReadCount,
                WriteCount = DiskIoSession.WriteCount,
                ChecksumCount = Stats.ChecksumCount,
                Lookups = DiskIoSession.Lookups,
                CachedLookups = DiskIoSession.CachedLookups
            });
        }
Beispiel #29
0
        public void TestRemoveValueShallow()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J


            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);

            string expected;
            string actual;

            tree.RemoveValue(D, true);

            //K
            //|
            //A     B
            //|      \
            //C       E
            //       / \
            // F  G  H  I
            //     \/
            //     J
            expected = "CAKJHIEBFG";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree.RemoveValue(B, true);
            expected = "CAKFJGHIE";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree.RemoveValue(J, true);
            expected = "CAKFGHIE";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree.RemoveValue(G, true);
            expected = "CAKFHIE";
            actual   = GetForeachRepresentation(tree);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");
        }
 internal SortedTreeTableReadSnapshot(ReadSnapshot currentTransaction, SubFileName fileName)
 {
     try
     {
         m_subStream    = currentTransaction.OpenFile(fileName);
         m_binaryStream = new BinaryStream(m_subStream);
         m_tree         = SortedTree <TKey, TValue> .Open(m_binaryStream);
     }
     catch
     {
         Dispose();
         throw;
     }
 }
Beispiel #31
0
        public void TestConnectTheTreeToTheNode()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            SortedTree <ClassAsTreeValue <string> > tree2 = tree.GetSubtreeFromNode(B);

            //tree2:
            //   B
            //   |
            //   E
            //  / \
            // H  I
            // |
            // J
            AreEqualGetFroeachRepresentationHelper("JHIEB", tree2, "prep step1");
            tree2.RemoveValue(J, false);
            AreEqualGetFroeachRepresentationHelper("HIEB", tree2, "prep step2");
            tree.RemoveValue(B, false);
            AreEqualGetFroeachRepresentationHelper("CFJGDAK", tree, "prep step3");

            //main test
            //K
            //|
            //A
            //|\ 
            //C D
            // / \ 
            // F  G
            //     \
            //     J
            //    /
            //   B
            //   |
            //   E
            //  / \
            // H  I
            tree.ConnectTheTreeToTheNode(J, 0, tree2, 0);
            AreEqualGetFroeachRepresentationHelper("CFHIEBJGDAK", tree, "main test");
        }
        /// <inheritdoc />
        public Task Analyze(SyntaxNode node, CancellationToken token)
        {
            if (node is null)
            {
                return(Task.CompletedTask);
            }

            var root = new SortedTree <CodeStructureItem>(new CodeStructureItem()
            {
                Name = "File"
            });
            var memberDeclarations = node
                                     .DescendantNodes(_ => true)
                                     .OfType <T>()
                                     .Where(x => KnownNodeTypes.Contains(x.GetType()));

            foreach (var declaration in memberDeclarations)
            {
                foreach (var mappedItem in NodeMapper.MapItem(declaration))
                {
                    var element = new SortedTree <CodeStructureItem>(mappedItem, declaration);
                    var parent  = root.FirstOrDefault(x => x.Meta == declaration.Parent) ?? root;
                    if (NeedsMetaNode(declaration))
                    {
                        var realParent = parent.Children.FirstOrDefault(x => x.Data.GetType() == element.Data.GetType() && x.Data.IsMeta);
                        if (realParent is null)
                        {
                            var metaData = RoslynMetaNodeCreator.Create(element.Data);
                            var metaNode = new SortedTree <CodeStructureItem>(metaData);
                            parent.Add(metaNode);
                            parent = metaNode;
                        }
                        else
                        {
                            parent = realParent;
                        }
                    }

                    parent.Add(element);
                }
            }

            NodeList = root.Skip(1).ToList();

            return(Task.CompletedTask);
        }
Beispiel #33
0
        static void Main(string[] args)
        {
            //SingleLinkedList<int> temp = new SingleLinkedList<int>();
            //for (int i = 0; i < 5; i++)
            //{
            //    temp.Add(i);
            //    Console.WriteLine(temp[i]);
            //}

            SortedTree<int> stree = new SortedTree<int>();
            stree.Add(20);
            stree.Add(8);
            stree.Add(12);
            stree.Add(9);
            stree.Add(14);
            stree.FindSpecialNode(10);
        }
Beispiel #34
0
        public void QueryChilds_ReturnsAllLayers()
        {
            // Arrange
            var sut = new SortedTree <int>(1);

            sut.Add(12).Add(122).Add(1222);
            sut.Add(13);
            sut.Add(11).Add(111).Add(1111);
            var expected = new List <int> {
                1, 11, 111, 1111, 12, 122, 1222, 13
            };

            // Act
            var result = sut.Select(x => x.Data).ToList();

            // Assert
            CollectionAssert.AreEqual(expected, result, $"{string.Join(",", expected.Select(x => x.ToString()))} => {string.Join(",", result.Select(x => x.ToString()))}");
        }
Beispiel #35
0
 public void AddRange_NullPassedAsElementsAlternativeTraverse_ShouldThrowArgumentException()
 {
     var st = new SortedTree<int>(true);
     Assert.Throws<ArgumentException>(() => st.AddRange(null));
 }
Beispiel #36
0
 public void AddRange_NullPassedAsElements_ShouldThrowArgumentException()
 {
     var st = new SortedTree<int>();
     Assert.Throws<ArgumentException>(() => st.AddRange(null));
 }
Beispiel #37
0
        public void AddRange_TwoSameElements_ShouldThrowArgumentException()
        {
            var st = new SortedTree<int>();

            Assert.Throws<ArgumentException>(() => st.AddRange(new List<int> { 3, 23, 3, }));
        }
Beispiel #38
0
        public void Travers_EmptyListAlternativeTraverse_ShouldReturnEmptyCollection()
        {
            var st = new SortedTree<int>(true);

            CollectionAssert.AreEqual(new List<int>(), st.Traverse());
        }