Exemple #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);
            }
        }
Exemple #2
0
        public void Delete(TKey Key)
        {
            BNode <T, TKey> Root = BNode <T, TKey> .DiskRead(File, Degree, RootPointer, TFactory, TKeyFactory);

            Root.Delete(File, Key);

            if (!Root.Leaf && Root.N == 0)
            {
                Root = BNode <T, TKey> .DiskRead(File, Degree, Root.ChildrenPointers[0], TFactory, TKeyFactory);
            }
            Root.DiskWrite(File, SizesNSpecialCharacters.HeaderSizeInBytes);
        }
Exemple #3
0
        private void Insert(int CrawlerPointer, TKey Key, T Value)
        {
            BNode <T, TKey> Crawler = BNode <T, TKey> .DiskRead(File, Degree, CrawlerPointer, TFactory, TKeyFactory);

            if (Crawler.Leaf)
            {
                MoveUp(Crawler, Key, Value, int.MinValue);
                UpdateHeader();
            }
            else
            {
                Insert(Crawler.ChildrenPointers[Crawler.FirstPointerOfNodeContaining(Key)], Key, Value);
            }
        }
Exemple #4
0
        private BNode <T, TKey> BTreeSearch(int CrawlerPointer, TKey Key, out int Pointer)
        {
            BNode <T, TKey> Crawler = BNode <T, TKey> .DiskRead(File, Degree, CrawlerPointer, TFactory, TKeyFactory);

            Pointer = Crawler.PrecisePointer(Key);
            if (Pointer != -1)
            {
                return(Crawler);
            }
            else
            {
                if (Crawler.Leaf)
                {
                    return(null);
                }
                else
                {
                    int FirstPointerOfNodeContaining = Crawler.FirstPointerOfNodeContaining(Key);
                    return(BTreeSearch(Crawler.ChildrenPointers[FirstPointerOfNodeContaining], Key, out Pointer));
                }
            }
        }