Exemple #1
0
        private void DeleteFromInternalNode(FileStream File, int i)
        {
            TKey            Key = Keys[i];
            BNode <T, TKey> y   = DiskRead(File, Degree, ChildrenPointers[i], ContentFactory, KeyFactory);

            if (y.N >= (Degree / 2 - 1))
            {
                TKey KPrime = y.LeftGreatest(File);
                y.Delete(File, KPrime);
                Keys[i] = KPrime;
            }
            else
            {
                BNode <T, TKey> z = DiskRead(File, Degree, ChildrenPointers[i + 1], ContentFactory, KeyFactory);

                if (z.N >= ((Degree / 2) - 1))
                {
                    TKey KPrime = z.RightLowest(File);
                    z.Delete(File, KPrime);
                    Keys[i] = KPrime;
                }
                else
                {
                    y.Keys[y.N] = Key;
                    for (int j = 0; j < z.N; j++)
                    {
                        y.Keys[y.N + j + 1] = z.Keys[j];
                    }
                    if (!y.Leaf)
                    {
                        for (int j = 0; j <= z.N; j++)
                        {
                            y.Keys[y.N + j + 1] = z.Keys[j];
                        }
                    }

                    for (int j = i + 1; j < N; j++)
                    {
                        Keys[j - 1]         = Keys[j];
                        ChildrenPointers[j] = ChildrenPointers[j + 1];
                    }
                    Keys[N - 1]         = KeyFactory.CreateNull();
                    ChildrenPointers[N] = SizesNSpecialCharacters.NullPointer;

                    DiskWrite(File, 65);
                    y.DiskWrite(File, 65);
                    z.DiskWrite(File, 65);
                    y.Delete(File, Key);
                }
            }

            DiskWrite(File, 65);
        }
Exemple #2
0
        internal void Delete(FileStream Stream, TKey Key)
        {
            if (Leaf)
            {
                DeleteFromLeaf(Stream, Key);
            }
            else
            {
                int i = 0;

                while (i < N && Keys[i].CompareTo(Key) < 0)
                {
                    i++;
                }
                if (i < N && Keys[i].CompareTo(Key) == 0)
                {
                    DeleteFromInternalNode(Stream, i);
                }
                else
                {
                    BNode <T, TKey> Child = DiskRead(Stream, Degree, ChildrenPointers[i], ContentFactory, KeyFactory);
                    EnsureFullEnough(Stream, i);
                    Child.Delete(Stream, Key);
                }
            }
        }
Exemple #3
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);
        }