Skip to content

Commit 94a9b38

Browse files
author
fuli
committed
update btree -- add procedure
1 parent a95d61a commit 94a9b38

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

include/btree.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,9 @@ namespace alg {
411411

412412
// remove key[i] from x and also the child
413413
// shrink the size & set the child-0 to left
414-
int j;
415-
for (j=i;j<x->n-1;j++) {
416-
x->key[j] = x->key[j+1];
417-
}
418-
419-
for (j=i+1;j<x->n;j++) {
420-
x->c[j] = x->c[j+1];
421-
}
422-
x->n = x->n - 1;
414+
delete_i(x, i);
423415

416+
int j;
424417
// append x.c[i] into left sibling
425418
for (j=0;j<ci->n;j++) {
426419
left->key[left->n + j] = ci->key[j];
@@ -450,16 +443,9 @@ namespace alg {
450443
ci->n = ci->n + 1;
451444
// remove key[i] from x and also the child
452445
// shrink the size & set the child-0 to ci
453-
int j;
454-
for (j=i;j<x->n-1;j++) {
455-
x->key[j] = x->key[j+1];
456-
}
457-
458-
for (j=i+1;j<x->n;j++) {
459-
x->c[j] = x->c[j+1];
460-
}
461-
x->n = x->n - 1;
446+
delete_i(x, i);
462447

448+
int j;
463449
// append right sibling into x.c[i]
464450
for (j=0;j<right->n;j++) {
465451
ci->key[ci->n + j] = right->key[j];
@@ -490,6 +476,21 @@ namespace alg {
490476
}
491477
}
492478

479+
/**
480+
* delete ith node
481+
*/
482+
void delete_i(node x, int32_t i) {
483+
int j;
484+
for (j=i;j<x->n-1;j++) {
485+
x->key[j] = x->key[j+1];
486+
}
487+
488+
for (j=i+1;j<x->n;j++) {
489+
x->c[j] = x->c[j+1];
490+
}
491+
x->n = x->n - 1;
492+
}
493+
493494
/**
494495
* Load the root block
495496
*/

0 commit comments

Comments
 (0)