-BtLatchSet *rset, *pset, *rpset;
-BtPool *rpool, *ppool, *rppool;
-BtPage rpage, ppage, rppage;
-uid right, parent, rparent;
-BtKey ptr;
-uint idx;
-
- // cache node's parent page
-
- parent = bt->page_no;
- ppage = bt->page;
- ppool = bt->pool;
- pset = bt->set;
-
- // lock and map our right page
- // it cannot be NULL because of the stopper
- // in the last right page
-
- bt_lockpage (BtLockWrite, set);
-
- // if we aren't dead yet
-
- if( page->act )
- goto rmergexit;
-
- if( right = bt_getid (page->right) )
- if( rpool = bt_pinpool (bt, right) )
- rpage = bt_page (bt, rpool, right);
- else
- return bt->err;
- else
- return bt->err = BTERR_struct;
-
- rset = bt_pinlatch (bt, right);
-
- // find our right neighbor
-
- if( ppage->act > 1 ) {
- for( idx = slot; idx++ < ppage->cnt; )
- if( !slotptr(ppage, idx)->dead )
- break;
-
- if( idx > ppage->cnt )
- return bt->err = BTERR_struct;
-
- // redirect right neighbor in parent to left node
-
- bt_putid(slotptr(ppage,idx)->id, page_no);
- }
-
- // if parent has only our deleted page, e.g. no right neighbor
- // prepare to merge parent itself
-
- if( ppage->act == 1 ) {
- if( rparent = bt_getid (ppage->right) )
- if( rppool = bt_pinpool (bt, rparent) )
- rppage = bt_page (bt, rppool, rparent);
- else
- return bt->err;
- else
- return bt->err = BTERR_struct;
-
- rpset = bt_pinlatch (bt, rparent);
- bt_lockpage (BtLockWrite, rpset);
-
- // find our right neighbor on right parent page
-
- for( idx = 0; idx++ < rppage->cnt; )
- if( !slotptr(rppage, idx)->dead ) {
- bt_putid (slotptr(rppage, idx)->id, page_no);
- break;
- }
-
- if( idx > rppage->cnt )
- return bt->err = BTERR_struct;
- }