Beispiel #1
0
        // removes the leftmost leaf from the tree
        public override IMemTreeNode SnipLeftLeaf()
        {
            IMemTreeNode newLeftChild = leftChild.SnipLeftLeaf();

            if (newLeftChild == null)
            {   // leftChild is a leaf node
                return(rightChild);
            }
            else
            {
                leftChild        = newLeftChild;
                contiguousBlocks = (leftChild.ContiguousBlocks < rightChild.ContiguousBlocks) ? rightChild.ContiguousBlocks : leftChild.ContiguousBlocks;
                return(this);
            }
        }
Beispiel #2
0
 private IMemTreeNode Merge()
 {
     if (rightChild is ContentNode)
     {
         if (leftChild is ContentNode)
         {
             // if they're both contentnodes, we can just substitute them with a single new contentnode
             return(new ContentNode()
             {
                 FirstBlock = leftChild.FirstBlock, LastBlock = rightChild.LastBlock
             });
         }
         else
         {   // right is a contentnode, but left isn't
             // merge the right contentnode into the lefttree
             leftChild.ExpandRightLeaf(rightChild.LastBlock - leftChild.RightLeaf.LastBlock);
             return(leftChild);
         }
     }
     else if (leftChild is ContentNode)
     {   // left is a contentnode, but right isn't
         // merge the left contentnode into the righttree
         rightChild.ExpandLeftLeaf(rightChild.LeftLeaf.FirstBlock - leftChild.FirstBlock);
         return(rightChild);
     }
     else
     {   // both left and right are index nodes. f**k it.
         // snip the leftmost leaf off the right tree
         IMemTreeNode snipped = rightChild.LeftLeaf;
         rightChild = rightChild.SnipLeftLeaf();
         // append that to the rightmost leaf of the left tree
         leftChild.RightLeaf.LastBlock = snipped.LastBlock;
         contiguousBlocks = (leftChild.ContiguousBlocks < rightChild.ContiguousBlocks) ? rightChild.ContiguousBlocks : leftChild.ContiguousBlocks;
         return(this);
     }
 }