コード例 #1
0
        public void TestBorrowRight()
        {
            var pageStore = new MemoryPageStore(4096);
            var config = new BPlusTreeConfiguration(pageStore, 8, 8, 4096);
            var leftNode = new LeafNode(pageStore.Create(0), 0, 0, config);
            var rightNode = new LeafNode(pageStore.Create(0), 0, 0, config);

            byte[] testBytes = new byte[] { 1, 2, 3, 4 };

            leftNode.Insert(1, BitConverter.GetBytes(1ul), testBytes);
            leftNode.Insert(1, BitConverter.GetBytes(2ul), testBytes);

            rightNode.Insert(1, BitConverter.GetBytes(10ul), testBytes);
            rightNode.Insert(1, BitConverter.GetBytes(11ul), testBytes);
            rightNode.Insert(1, BitConverter.GetBytes(12ul), testBytes);
            rightNode.Insert(1, BitConverter.GetBytes(13ul), testBytes);
            rightNode.Insert(1, BitConverter.GetBytes(14ul), testBytes);

            Assert.IsTrue(leftNode.RedistributeFromRight(1, rightNode));
            Assert.IsTrue(leftNode.KeyCount == 3);
            TestUtils.AssertBuffersEqual(BitConverter.GetBytes(10ul), leftNode.RightmostKey);
            TestUtils.AssertBuffersEqual(BitConverter.GetBytes(11ul), rightNode.LeftmostKey);
            Assert.IsTrue(rightNode.KeyCount == 4);
            Assert.IsFalse(leftNode.RedistributeFromRight(1, rightNode));
        }
コード例 #2
0
        public void TestLeafNodeSplit()
        {
            var pageStore = new MemoryPageStore(4096);
            var config = new BPlusTreeConfiguration(pageStore, 8, 8, 4096);
            var firstNode = new LeafNode(pageStore.Create(0), 0, 0, config);
            var testBytes = new byte[]{1,2,3,4,5,6,7,8};
            for (int i = 0; i < config.LeafLoadFactor; i++)
            {
                firstNode.Insert(0, BitConverter.GetBytes((ulong)i), testBytes);
            }

            var secondNodePage = pageStore.Create(0);
            var splitKey = new byte[8];
            var secondNode = firstNode.Split(0, secondNodePage, out splitKey);

            Assert.AreEqual(config.LeafSplitIndex, firstNode.KeyCount);
            Assert.AreEqual(config.LeafLoadFactor - config.LeafSplitIndex, secondNode.KeyCount);

            var firstNodePage = pageStore.Retrieve(0, null);
            var firstNodeKeyCount = BitConverter.ToInt32(firstNodePage.Data, 0);
            secondNodePage = pageStore.Retrieve(1, null);
            var secondNodeKeyCount = BitConverter.ToInt32(secondNodePage.Data, 0);
            Assert.AreEqual(config.LeafSplitIndex, firstNodeKeyCount);
            Assert.AreEqual(config.LeafLoadFactor - config.LeafSplitIndex, secondNodeKeyCount);
            
        }
コード例 #3
0
 public void TestRightShiftFrom()
 {
     var pageStore = new MemoryPageStore(1024);
     var config = new BPlusTreeConfiguration( pageStore, 8, 8, 1024);
     var n = new InternalNode(pageStore.Create(0), BitConverter.GetBytes(50ul), 2,3, config);
     n.Insert(1, BitConverter.GetBytes(100ul), 4);
     Assert.AreEqual(50ul, BitConverter.ToUInt64(n.LeftmostKey, 0));
     Assert.AreEqual(100ul, BitConverter.ToUInt64(n.RightmostKey, 0));
 }
コード例 #4
0
        public void TestRightShiftFrom()
        {
            var pageStore = new MemoryPageStore(1024);
            var config    = new BPlusTreeConfiguration(pageStore, 8, 8, 1024);
            var n         = new InternalNode(pageStore.Create(0), BitConverter.GetBytes(50ul), 2, 3, config);

            n.Insert(1, BitConverter.GetBytes(100ul), 4);
            Assert.AreEqual(50ul, BitConverter.ToUInt64(n.LeftmostKey, 0));
            Assert.AreEqual(100ul, BitConverter.ToUInt64(n.RightmostKey, 0));
        }