Beispiel #1
0
        public virtual void TestDeleteInsert100000()
        {
            NeoDatis.Btree.IBTree btree = GetBTree(3);
            int size = 200000;

            for (int i = 0; i < size; i++)
            {
                btree.Insert(i, "key " + i);
            }
            AssertEquals(size, btree.GetSize());
            for (int i = 0; i < size; i++)
            {
                AssertEquals("key " + i, btree.Delete(i, "key " + i));
            }
            AssertEquals(0, btree.GetSize());
            AssertEquals(1, btree.GetHeight());
            AssertEquals(0, btree.GetRoot().GetNbKeys());
            AssertEquals(0, btree.GetRoot().GetNbChildren());
            for (int i = 0; i < size; i++)
            {
                btree.Insert(size + i, "key " + (i + size));
            }
            for (int i = 0; i < size; i++)
            {
                AssertEquals("key " + (i + size), btree.Delete(i + size, "key " + (i + size)));
            }
            AssertEquals(0, btree.GetSize());
            AssertEquals(1, btree.GetHeight());
            AssertEquals(0, btree.GetRoot().GetNbKeys());
            AssertEquals(0, btree.GetRoot().GetNbChildren());
        }
Beispiel #2
0
        public virtual void TestDelete1()
        {
            NeoDatis.Btree.IBTree btree = GetBTree(10);
            int  size = 500000;
            long t0   = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();

            for (int i = 0; i < size; i++)
            {
                btree.Insert(i, "key " + i);
            }
            long t1 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();

            // println("insert time=" + (t1-t0));
            AssertEquals(size, btree.GetSize());
            AssertEquals("key 499999", btree.Delete(499999, "key 499999"));
        }
Beispiel #3
0
        public virtual void TestDelete3()
        {
            NeoDatis.Btree.IBTree btree = GetBTree(3);
            int size = 10;

            for (int i = 0; i < size; i++)
            {
                btree.Insert(i, "key " + i);
            }
            AssertEquals(size, btree.GetSize());
            for (int i = 0; i < size; i++)
            {
                AssertEquals("key " + i, btree.Delete(i, "key " + i));
            }
            AssertEquals(0, btree.GetSize());
        }
Beispiel #4
0
 /// <exception cref="System.Exception"></exception>
 private void TestDelete(int[] numbers)
 {
     NeoDatis.Btree.IBTree btree = GetBTree(2);
     for (int i = 0; i < numbers.Length; i++)
     {
         btree.Insert(numbers[i], "v " + numbers[i]);
     }
     AssertEquals(numbers.Length, btree.GetSize());
     for (int i = 0; i < numbers.Length; i++)
     {
         AssertEquals("v " + (i + 1), btree.Delete(i + 1, "v " + (i + 1)));
     }
     AssertEquals(0, btree.GetSize());
     AssertEquals(1, btree.GetHeight());
     AssertEquals(0, btree.GetRoot().GetNbKeys());
     AssertEquals(0, btree.GetRoot().GetNbChildren());
 }
Beispiel #5
0
        public virtual void TestDelete1000_3()
        {
            NeoDatis.Btree.IBTree btree = GetBTree(3);
            int size = 1000;

            for (int i = 0; i < size; i++)
            {
                btree.Insert(i, "value " + i);
            }
            AssertEquals(size, btree.GetSize());
            for (int i = size - 1; i >= 0; i--)
            {
                AssertEquals("value " + i, btree.Delete(i, "value " + i));
            }
            AssertEquals(0, btree.GetSize());
            AssertEquals(1, btree.GetHeight());
            AssertEquals(0, btree.GetRoot().GetNbKeys());
            AssertEquals(0, btree.GetRoot().GetNbChildren());
        }
Beispiel #6
0
        public virtual void TestDelete27()
        {
            NeoDatis.Btree.IBTree tree = GetBTree(3);
            tree.Insert("P", "P");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey PNode = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                             )tree.GetRoot();
            NeoDatis.Btree.IBTreeNodeOneValuePerKey CGMNode = GetBTreeNode(tree, "cgm");
            CGMNode.InsertKeyAndValue("C", "C");
            CGMNode.InsertKeyAndValue("G", "G");
            CGMNode.InsertKeyAndValue("M", "M");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey TXNode = GetBTreeNode(tree, "tx");
            TXNode.InsertKeyAndValue("T", "T");
            TXNode.InsertKeyAndValue("X", "X");
            PNode.SetChildAt(CGMNode, 0);
            PNode.SetChildAt(TXNode, 1);
            PNode.SetNbChildren(2);
            NeoDatis.Btree.IBTreeNodeOneValuePerKey ABNode = GetBTreeNode(tree, "ab");
            ABNode.InsertKeyAndValue("A", "A");
            ABNode.InsertKeyAndValue("B", "B");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey DEFode = GetBTreeNode(tree, "def");
            DEFode.InsertKeyAndValue("D", "D");
            DEFode.InsertKeyAndValue("E", "E");
            DEFode.InsertKeyAndValue("F", "F");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey JKLNode = GetBTreeNode(tree, "jkl");
            JKLNode.InsertKeyAndValue("J", "J");
            JKLNode.InsertKeyAndValue("K", "K");
            JKLNode.InsertKeyAndValue("L", "L");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey NONode = GetBTreeNode(tree, "no");
            NONode.InsertKeyAndValue("N", "N");
            NONode.InsertKeyAndValue("O", "O");
            CGMNode.SetChildAt(ABNode, 0);
            CGMNode.SetChildAt(DEFode, 1);
            CGMNode.SetChildAt(JKLNode, 2);
            CGMNode.SetChildAt(NONode, 3);
            CGMNode.SetNbChildren(4);
            NeoDatis.Btree.IBTreeNodeOneValuePerKey QRSNode = GetBTreeNode(tree, "qrs");
            QRSNode.InsertKeyAndValue("Q", "Q");
            QRSNode.InsertKeyAndValue("R", "R");
            QRSNode.InsertKeyAndValue("S", "S");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey UVNode = GetBTreeNode(tree, "uv");
            UVNode.InsertKeyAndValue("U", "U");
            UVNode.InsertKeyAndValue("V", "V");
            NeoDatis.Btree.IBTreeNodeOneValuePerKey YZNode = GetBTreeNode(tree, "yz");
            YZNode.InsertKeyAndValue("Y", "Y");
            YZNode.InsertKeyAndValue("Z", "Z");
            TXNode.SetChildAt(QRSNode, 0);
            TXNode.SetChildAt(UVNode, 1);
            TXNode.SetChildAt(YZNode, 2);
            TXNode.SetNbChildren(3);
            string s1 = "h=1:[P]" + "h=2:[C,G,M][T,X]" + "h=3:[A,B][D,E,F][J,K,L][N,O][Q,R,S][U,V][Y,Z]";
            // case 1
            string s2AfterDeleteingF = "h=1:[P]" + "h=2:[C,G,M][T,X]" + "h=3:[A,B][D,E][J,K,L][N,O][Q,R,S][U,V][Y,Z]";
            object F = tree.Delete("F", "F");

            AssertEquals("F", F);
            string s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false)
                       .ToString();

            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty);
            AssertEquals(s2AfterDeleteingF, s);
            // case 2a
            string s2AfterDeleteingM = "h=1:[P]" + "h=2:[C,G,L][T,X]" + "h=3:[A,B][D,E][J,K][N,O][Q,R,S][U,V][Y,Z]";
            object M = tree.Delete("M", "M");

            AssertEquals("M", M);
            s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString
                    ();
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty);
            AssertEquals(s2AfterDeleteingM, s);
            // case 2c
            string s2AfterDeleteingG = "h=1:[P]" + "h=2:[C,L][T,X]" + "h=3:[A,B][D,E,J,K][N,O][Q,R,S][U,V][Y,Z]";
            object G = tree.Delete("G", "G");

            AssertEquals("G", G);
            s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString
                    ();
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty);
            AssertEquals(s2AfterDeleteingG, s);
            // case 3b
            string s2AfterDeleteingD = "h=1:[C,L,P,T,X]" + "h=2:[A,B][E,J,K][N,O][Q,R,S][U,V][Y,Z]";
            object D = tree.Delete("D", "D");

            // assertEquals(2, tree.getHeight());
            AssertEquals("D", D);
            s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString
                    ();
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "h=3:", string.Empty);
            AssertEquals(s2AfterDeleteingD, s);
            // case 3a
            string s2AfterDeleteingB = "h=1:[E,L,P,T,X]" + "h=2:[A,C][J,K][N,O][Q,R,S][U,V][Y,Z]";
            object B = tree.Delete("B", "B");

            AssertEquals("B", B);
            s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString
                    ();
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty);
            s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "h=3:", string.Empty);
            AssertEquals(s2AfterDeleteingB, s);
        }