|
|
|
|
Fixing the underflow condition:
|
|
Goal:
|
/* ==============================================================
Delete( x ) from B+-tree
Input: search key x that we wish to delete from B+-tree index
============================================================== */
Delete( search key x ) // Algorithm will also delete the record pointer for x
{
Use the B-tree search algorithm to find
the leaf node D where the x belongs
if ( x not found in D )
{
return; // Done. We can't delete a non-existing search key
}
else
{
Shift keys to delete the key x
and its record ptr from the node
}
/* ==============================================
We delete a search key (+ record ptr) from D
===> Node D may become underflow !!!
Check and handle underflow condition
============================================== */
if ( D has ≥ ⌈n/2⌉ keys /* Node is at least half full*/ )
{
return; // No underflow, done
}
else
{
/* ---------------------------------------------------------
D underflowed: fix the size of D with transfer or merge
--------------------------------------------------------- */
if ( leftSibling(D) has ≥ ⌈n/2⌉ + 1 keys )
{
1. transfer last key and ptr from leftSibling(D) into D;
2. update the search key in the parent node;
|
Notice that:
|