Пример #1
0
 public bool Delete(TKey key)
 {
     return(array.Delete(new Node()
     {
         Key = key, Value = default(TValue)
     }));
 }
Пример #2
0
        public void Test_RBTREE_DELETE()
        {
            RBTree rbTree = new RBTree();

            System.Collections.Generic.IList <IDirectoryEntry> repo = GetDirectoryRepository(25);


            foreach (var item in repo)
            {
                rbTree.Insert(item);
            }

            try
            {
                IRBNode n;
                rbTree.Delete(DirectoryEntry.Mock("5", StgType.StgInvalid), out n);
                rbTree.Delete(DirectoryEntry.Mock("24", StgType.StgInvalid), out n);
                rbTree.Delete(DirectoryEntry.Mock("7", StgType.StgInvalid), out n);
            }
            catch (Exception ex)
            {
                Assert.Fail("Item removal failed: " + ex.Message);
            }



            //    CFItem c;
            //    bool s = rbTree.TryLookup(new CFMock("7", StgType.StgStream), out c);


            //    Assert.IsFalse(s);

            //    c = null;

            //    Assert.IsTrue(rbTree.TryLookup(new CFMock("6", StgType.StgStream), out c));
            //    Assert.IsTrue(c.IsStream);
            //    Assert.IsTrue(rbTree.TryLookup(new CFMock("12", StgType.StgStream), out c));
            //    Assert.IsTrue(c.Name == "12");


            //}
        }
Пример #3
0
        public void Delete_RedNode_With_NoChildren_Should_TriggerRotations_AndRecoloring()
        {
            RBTree <int> tree = new RBTree <int>();

            for (int i = 0; i < 10; i++)
            {
                tree.Add(i);
            }
            tree.Delete(tree.GetNode(7));
            var exception = Assert.Throws <KeyNotFoundException>(() => tree.GetNode(7));

            Assert.True(exception.Message == "Key not found.");
        }
Пример #4
0
        public void Delete()
        {
            RBTree <int> testClass = GetTree();

            //  ____12_____
            // _5_   ____18___
            // 2 9 __15__   19
            //     13  17
            testClass.Delete(12);

            //  ____13_____
            // _5_   ____18___
            // 2 9   15__   19
            //         17
            Assert.Null(testClass.Root.ParentNode);

            Assert.Equal(testClass.Root.Value, 13);
            Assert.Equal(testClass.Root.LeftNode.Value, 5);
            Assert.Equal(testClass.Root.LeftNode.LeftNode.Value, 2);
            Assert.Equal(testClass.Root.LeftNode.RightNode.Value, 9);
            Assert.Equal(testClass.Root.RightNode.Value, 18);
            Assert.Equal(testClass.Root.RightNode.LeftNode.Value, 15);
            Assert.Equal(testClass.Root.RightNode.LeftNode.RightNode.Value, 17);
            Assert.Equal(testClass.Root.RightNode.RightNode.Value, 19);

            Assert.Equal(testClass.Root.LeftNode.ParentNode.Value, 13);                     //5
            Assert.Equal(testClass.Root.RightNode.ParentNode.Value, 13);                    //18
            Assert.Equal(testClass.Root.LeftNode.LeftNode.ParentNode.Value, 5);             //2
            Assert.Equal(testClass.Root.LeftNode.RightNode.ParentNode.Value, 5);            //9
            Assert.Equal(testClass.Root.RightNode.LeftNode.ParentNode.Value, 18);           //15
            Assert.Equal(testClass.Root.RightNode.RightNode.ParentNode.Value, 18);          //19
            Assert.Equal(testClass.Root.RightNode.LeftNode.RightNode.ParentNode.Value, 15); //17

            Assert.Null(testClass.Root.LeftNode.LeftNode.LeftNode);                         //2
            Assert.Null(testClass.Root.LeftNode.LeftNode.RightNode);                        //2
            Assert.Null(testClass.Root.LeftNode.RightNode.LeftNode);                        //9
            Assert.Null(testClass.Root.LeftNode.RightNode.RightNode);                       //9
            Assert.Null(testClass.Root.RightNode.RightNode.LeftNode);                       //19
            Assert.Null(testClass.Root.RightNode.RightNode.RightNode);                      //19
            Assert.Null(testClass.Root.RightNode.LeftNode.LeftNode);                        //15
            Assert.Null(testClass.Root.RightNode.LeftNode.RightNode.LeftNode);              //17
            Assert.Null(testClass.Root.RightNode.LeftNode.RightNode.RightNode);             //17
        }
Пример #5
0
        private IEnumerator Start()
        {
            RBTree <int> rbMap = new RBTree <int>();

            int[] nums = new int[100000];
            for (int i = 0; i < nums.Length; ++i)
            {
                nums[i] = i;
            }

            int counter = 0;

            while (true)
            {
                ++counter;

                //追加
                var sw = System.Diagnostics.Stopwatch.StartNew();
                for (int i = 0; i < nums.Length; ++i)
                {
                    rbMap.Insert(nums[i]);
                }
                sw.Stop();
                Debug.Log("Insert(" + nums.Length + ") is " + sw.ElapsedMilliseconds + " : Avg(" + counter + ") is " + (insertSum += sw.ElapsedMilliseconds) / counter);
                sw.Reset();

                //確認
                //Debug.Log(rbMap);

                //削除
                sw.Start();
                for (int i = 0; i < nums.Length; ++i)
                {
                    rbMap.Delete(nums[i]);
                }
                sw.Stop();
                Debug.Log("Delete(" + nums.Length + ") is " + sw.ElapsedMilliseconds + " : Avg(" + counter + ") is " + (deleteSum += sw.ElapsedMilliseconds) / counter);
                Debug.Log(rbMap);

                yield return(new WaitForSeconds(0.4f));
            }
        }
Пример #6
0
        private string DeleteTimeTest(int countForDelete)
        {
            sw = Stopwatch.StartNew();
            for (int i = 1; i <= countForDelete; i++)
            {
                tree.Delete(i);
                //DisplayTree();
            }

            /*tree.Delete(27);
            *  tree.Delete(22);
            *  tree.Delete(25);
            *  tree.Delete(15);
            *  tree.Delete(17);
            *  tree.Delete(11);
            *  DisplayTree();
            *  tree.Delete(6);
            *  tree.Delete(1);
            *  tree.Delete(8);
            *  tree.Delete(13);*/
            long elapsed  = sw.ElapsedMilliseconds;
            var  isPassed = true;
            var  treeList = tree.GetTree();

            for (int i = 1; i <= countForDelete; i++)
            {
                if (!treeList.Contains(i))
                {
                    continue;
                }
                isPassed = false;
                break;
            }
            var tmp = isPassed ? "passed in " : "failer in ";

            return(tmp + elapsed + "ms");
        }