Ejemplo n.º 1
0
        public void BalancedInsert()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            var customerRecord1 = CreateCustomer(500);

            tree.Insert(customerRecord1);
            tree.GetStringVersion().Should().Be("P:500");

            var customerRecord2 = CreateCustomer(400);

            tree.Insert(customerRecord2);
            tree.GetStringVersion().Should().Be("P:400|P:500");

            var customerRecord3 = CreateCustomer(300);

            tree.Insert(customerRecord3);
            tree.GetStringVersion().Should().Be("P:300|P:400|P:500");

            var customerRecord4 = CreateCustomer(350);

            tree.Insert(customerRecord4);
            tree.GetStringVersion().Should().Be("P:300|P:350|I:400|P:400|P:500");
        }
Ejemplo n.º 2
0
        public void ShouldStoreTwoRecord(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customer01 = CreateCustomer(100);

            tree.Insert(customer01);

            var cusomter02 = CreateCustomer(101);

            tree.Insert(cusomter02);

            var customers = tree.GetAll();

            customers.Should().HaveCount(2);

            customers[0].CustomerId.Should().Be(100);
            customers[0].Name.Should().Be(customer01.Name);

            customers[1].CustomerId.Should().Be(101);
            customers[1].Name.Should().Be(cusomter02.Name);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().Be("P:100|P:101");
        }
Ejemplo n.º 3
0
        public void BalancedInsert()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(500));
            tree.GetStringVersion().Should().Be("P:500");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:400|P:500");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:300|I:400|P:400|P:500");

            tree.Insert(CreateCustomer(350));
            tree.GetStringVersion().Should().Be("P:300|P:350|I:400|P:400|P:500");
        }
Ejemplo n.º 4
0
        public void RightSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110");

            tree.Insert(CreateCustomer(120));
            tree.GetStringVersion().Should().Be("P:100|I:110|P:110|P:120");

            tree.Insert(CreateCustomer(130));
            tree.GetStringVersion().Should().Be("P:100|I:110|P:110|I:120|P:120|P:130");
        }
Ejemplo n.º 5
0
        public void ShouldNotErrorWithZeroRecords(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customers = tree.GetAll();

            customers.Should().HaveCount(0);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().BeEmpty();
        }
Ejemplo n.º 6
0
        public void ShouldStoreSingleRecord(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customerRecord = CreateCustomer(100);

            tree.Insert(customerRecord);

            var customers = tree.GetAll();

            customers.Should().HaveCount(1);

            customers[0].CustomerId.Should().Be(100);
            customers[0].Name.Should().Be(customerRecord.Name);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().Be("P:100");
        }
Ejemplo n.º 7
0
        public void HighLevelIndexSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(200));
            tree.GetStringVersion().Should().Be("P:100|P:200");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:100|I:200|P:200|P:300");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|P:300");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(225));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|P:225|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(230));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(500));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|P:500");

            tree.Insert(CreateCustomer(600));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|P:600");

            tree.Insert(CreateCustomer(700));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|I:600|P:600|P:700");

            tree.Insert(CreateCustomer(800));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|I:600|P:600|I:700|P:700|P:800");
        }
Ejemplo n.º 8
0
        public void MiddleSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110");

            tree.Insert(CreateCustomer(120));
            tree.GetStringVersion().Should().Be("P:100|P:110|P:120");

            tree.Insert(CreateCustomer(130));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(111));
            tree.GetStringVersion().Should().Be("P:100|P:110|P:111|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(112));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(113));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|P:113|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(114));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(115));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|P:115|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(116));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|I:115|P:115|P:116|I:120|P:120|P:130");
        }
Ejemplo n.º 9
0
        public void LeftMostSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(200));
            tree.GetStringVersion().Should().Be("P:100|P:200");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:300");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:100|P:200|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(250));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:250|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(275));
            tree.GetStringVersion().Should().Be("P:100|P:200|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(225));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(150));
            tree.GetStringVersion().Should().Be("P:100|P:150|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(175));
            tree.GetStringVersion().Should().Be("P:100|P:150|P:175|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(125));
            tree.GetStringVersion().Should().Be("P:100|P:125|I:150|P:150|P:175|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");
        }