Example #1
0
 public BTree(int t, long root, Func <IFile, IFile, int> comparer, StreamManager manager)
 {
     this.t        = t;
     this.manager  = manager;
     this.comparer = comparer;
     this.root     = manager.DiskRead(root);
 }
Example #2
0
        private void InsertNonFull(Node x, IFile k)
        {
            int index = x.n - 1;

            if (x.leaf)
            {
                while (index >= 0 && comparer(k, x.key[index]) < 0)
                {
                    x.key[index + 1] = x.key[index];
                    index--;
                }
                x.key[index + 1] = k;
                x.n++;
                manager.DiskWrite(x);
            }
            else
            {
                while (index >= 0 && comparer(k, x.key[index]) < 0)
                {
                    index--;
                }
                index++;
                Node child = manager.DiskRead(x.c[index]);
                if (child.n == 2 * t - 1)
                {
                    SplitChild(child, x, index);
                    if (comparer(k, x.key[index]) >= 0)
                    {
                        child = manager.DiskRead(x.c[index + 1]);
                    }
                }
                InsertNonFull(child, k);
            }
        }