|
Goal:
|
/* ======================================================== Insert (x, RSub(x)) into the internal node N of B+-tree ======================================================== */ InsertInternal( x, rx, N ) { if ( N ≠ full ) { Shift keys to make room for x insert (x, rx) into its position in N return // Done } else { /* ------------------------------------------- Internal node N has: n keys + n+1 node ptrs: N: |p1|k1|p2|k2|....|pn|kn|pn+1| ------------------------------------------- */ Make the following virtual node by inserting x,rx in N: |p1|k1|p2|k2|...|x|rx|...|pn|kn|pn+1| (There are (n+2) pointers in this node !!!) Split this node into 3 parts: 1. Take the middle key out 2. L = the "left" half (use the old node to do this) 3. R = the "right" half (create a new node to do this) Let: m = ⌈(n+1)/2⌉ 1. Take km out 2. L = |p1|k1|p2|k2|...|pm-1|km-1|pm| (use old node N for L) 3. R = |pm+1|km+1|....|x|rx|...|pn|kn|pn+1| (use a new node for R) if ( N == root ) // N is same node as L { Make a new root node containing (L(=N), km, R) return; } else { InsertInternal( (km, R), parent(N)); // Recurse !! } } } |