Skip to content

Commit 4b04297

Browse files
author
fuli
committed
update btree.h
1 parent e72721a commit 4b04297

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

include/btree.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,15 @@ namespace alg {
8787
void Insert(int32_t k) {
8888
node r = m_root;
8989
if (r->n == 2*T - 1) {
90-
node s = (node)allocate_node();
9190
// place the old root node to the end of the file
9291
m_root->flag &= ~ONDISK;
9392
WRITE(m_root);
9493
// new root
94+
node s = (node)allocate_node();
9595
s->flag &= ~LEAF;
96-
s->offset = 0;
97-
s->n = 0;
9896
s->c[0] = m_root->offset;
99-
//free(m_root);
97+
// free old & set new
98+
free(m_root);
10099
m_root = s;
101100
split_child(s, 0);
102101
insert_nonfull(s, k);
@@ -110,7 +109,7 @@ namespace alg {
110109
* search a key, returns node and index
111110
*/
112111
search_r search(node x, int32_t k) {
113-
uint16_t i = 0;
112+
int32_t i = 0;
114113
search_r ret;
115114
while (i<x->n && k > x->key[i]) i++;
116115

@@ -178,7 +177,7 @@ namespace alg {
178177
z->flag |= (y->flag & LEAF);
179178
z->n = T - 1;
180179

181-
uint16_t j;
180+
int32_t j;
182181
for (j=0;j<T-1;j++) { // init z
183182
z->key[j] = y->key[j+T];
184183
}
@@ -204,7 +203,7 @@ namespace alg {
204203
x->key[j+1] = x->key[j];
205204
}
206205
x->key[i] = y->key[T-1];
207-
x->n = x->n +1;
206+
x->n = x->n+1;
208207
WRITE(x);
209208
}
210209

0 commit comments

Comments
 (0)