Exemplo n.º 1
0
        private void MoveUp(BNode <T, TKey> Crawler, TKey Key, T Value, int RightSibling)
        {
            if (!Crawler.Full)
            {
                Crawler.Insert(Key, Value, RightSibling);
                Crawler.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
                return;
            }
            BNode <T, TKey> Sibling = new BNode <T, TKey>(Degree, FirstAvailablePointer, Crawler.Parent, TFactory, TKeyFactory);

            FirstAvailablePointer++;
            TKey UpwardMovingKey   = TKeyFactory.CreateNull();
            T    UpwardMovingValue = TFactory.CreateNull();

            Crawler.Split(Key, Value, RightSibling, Sibling, ref UpwardMovingKey, UpwardMovingValue);
            BNode <T, TKey> Child = null;

            for (int i = 0; i < Sibling.ChildrenPointers.Count; i++)
            {
                if (Sibling.ChildrenPointers[i] != int.MinValue)
                {
                    Child = BNode <T, TKey> .DiskRead(File, Degree, Sibling.ChildrenPointers[i], TFactory, TKeyFactory);

                    Child.Parent = Sibling.Pointer;
                    Child.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
                }
                else
                {
                    break;
                }
            }
            if (Crawler.Parent == int.MinValue)
            {
                BNode <T, TKey> NewRoot = new BNode <T, TKey>(Degree, FirstAvailablePointer, int.MinValue, TFactory, TKeyFactory);
                FirstAvailablePointer++;
                NewRoot.ChildrenPointers[0] = Crawler.Pointer;
                NewRoot.Insert(UpwardMovingKey, UpwardMovingValue, Sibling.Pointer);
                Crawler.Parent = NewRoot.Pointer;
                Sibling.Parent = NewRoot.Pointer;
                RootPointer    = NewRoot.Pointer;
                NewRoot.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
                Crawler.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
                Sibling.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
            }
            else
            {
                Crawler.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
                Sibling.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);

                BNode <T, TKey> Parent = BNode <T, TKey> .DiskRead(File, Degree, Crawler.Parent, TFactory, TKeyFactory);

                MoveUp(Parent, UpwardMovingKey, UpwardMovingValue, Sibling.Pointer);
            }
        }