|
|
Goal:
|
/* ========================================================
Delete( x ) from B+-tree
======================================================== */
Delete( x )
{
Use the B-tree search algorithm to find
the leaf node L where the x belongs
if ( x not found )
{
return;
}
else
{
Shift keys to delete the key x
and its record ptr from the node
}
if ( L has ≥ ⌊(n+1)/2⌋ keys /* At least half full*/ )
{
return; // Done
}
else
{
/* ---------------------------------------------------------
L underflows: fix the size of L with transfer or merge
--------------------------------------------------------- */
if ( leftSibling(L) has ≥ ⌊(n+1)/2⌋ + 1 keys )
{
1. transfer last key and ptr from leftSibling(L) into L;
2. update the search key in the parent node;
|
Notice that:
|
|
Goal:
|
/* ========================================================
Delete( x, rx ) from a node N in B+-tree
======================================================== */
Delete( x, rx, N )
{
Delete x, rx from node N;
/* ====================================
Check for underflow condition...
==================================== */
if ( N has ≥ ⌊(n+1)/2⌋ pointers /* At least half full*/ )
{
return; // Done
}
else
{
/* ---------------------------------------------------------
N underflowed: fix the size of N with transfer or merge
--------------------------------------------------------- */
/* ========================================================
Always try transfer first !!!
(Merge is only possible if 2 nodes are half filled)
======================================================== */
if ( leftSibling(N) has ≥ ⌊(n+1)/2⌋ + 1 pointers )
{
1. transfer last key from leftSibling(N) through parent into N as the first key;
2. transfer right subtree link into N as the first link
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|