Пример #1
0
        public void AddValueToChild(TKeyType value, Pointer valuePointer)
        {
            BPlusTreeNode <TKeyType> target = ReadNode(GetTargetPointer(value));

            target.AddValue(value, valuePointer);
        }
Пример #2
0
        private void Split()
        {
            if (IsRoot)
            {
                int half = (int)Math.Ceiling(Values.Count / (double)2);
                List <BPlusTreeNodeValue> firstHalf  = Values.Take(half).ToList();
                List <BPlusTreeNodeValue> secondHalf = Values.Skip(half).ToList();

                BPlusTreeNode <TKeyType> leftChild = AddChild();
                leftChild.Values = firstHalf;
                leftChild.IsLeaf = IsLeaf;

                foreach (BPlusTreeNode <TKeyType> k in leftChild.Children)
                {
                    k.Parent = leftChild;
                }

                BPlusTreeNode <TKeyType> rightChild = AddChild();
                rightChild.Values = secondHalf.ToList();
                rightChild.IsLeaf = IsLeaf;

                foreach (BPlusTreeNode <TKeyType> k in rightChild.Children)
                {
                    k.Parent = rightChild;
                }

                BPlusTreeNodeValue middle = new BPlusTreeNodeValue {
                    Value = Values[half].Value, LeftPointer = leftChild.Page, RightPointer = rightChild.Page
                };
                Values = new List <BPlusTreeNodeValue> {
                    middle
                };

                if (leftChild.IsLeaf)
                {
                    leftChild.RightSiblingPointer = rightChild.Page;
                }

                if (rightChild.IsLeaf)
                {
                    rightChild.LeftSiblingPointer = leftChild.Page;
                }

                IsLeaf = false;
                Dirty  = true;
            }
            else
            {
                int half = Values.Count / 2;
                List <BPlusTreeNodeValue> firstHalf  = Values.Take(half).ToList();
                List <BPlusTreeNodeValue> secondHalf = Values.Skip(half).ToList();

                BPlusTreeNode <TKeyType> rightChild = Parent.AddChild();
                rightChild.Values = secondHalf;

                Values = firstHalf;

                if (IsLeaf)
                {
                    RightSiblingPointer           = rightChild.Page;
                    rightChild.LeftSiblingPointer = Page;
                    rightChild.IsLeaf             = true;
                }

                Parent.AddValueToSelf(new BPlusTreeNodeValue {
                    Value = secondHalf.First().Value, LeftPointer = Page, RightPointer = rightChild.Page
                });;

                Dirty = true;
            }
        }