File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ namespace alg {
87
87
s->flag &= ~LEAF;
88
88
s->flag |= ONDISK; // write to offset 0
89
89
s->offset = 0 ;
90
+ s->n = 0 ;
90
91
s->c [0 ] = m_root->offset ;
91
92
// free old & set new
92
93
free (m_root);
@@ -141,6 +142,7 @@ namespace alg {
141
142
i = i+1 ;
142
143
}
143
144
}
145
+ xi = READ (x, i); // reload x[i]
144
146
insert_nonfull (xi, k);
145
147
free (xi);
146
148
}
@@ -167,9 +169,6 @@ namespace alg {
167
169
std::auto_ptr<node_t > y (READ (x, i));
168
170
z->flag &= ~LEAF;
169
171
z->flag |= (y->flag & LEAF);
170
- printf (" leafz:%x\n " , z->flag );
171
- printf (" leafy:%x\n " , y->flag );
172
- printf (" leafx:%x offset:%x\n " , x->flag , x->offset );
173
172
z->n = T - 1 ;
174
173
175
174
int32_t j;
@@ -195,7 +194,7 @@ namespace alg {
195
194
for (j=x->n -1 ;j>=i;j--) { // move keys in x
196
195
x->key [j+1 ] = x->key [j];
197
196
}
198
- x->key [i] = y->key [T-1 ];
197
+ x->key [i] = y->key [T-1 ]; // copy the middle element of y into x
199
198
x->n = x->n +1 ;
200
199
WRITE (x);
201
200
}
@@ -209,7 +208,7 @@ namespace alg {
209
208
read (fd, xi, BLOCKSIZE);
210
209
return (node)xi;
211
210
}
212
-
211
+
213
212
/* *
214
213
* update a node struct to file, create if offset is -1.
215
214
*/
Original file line number Diff line number Diff line change @@ -6,13 +6,8 @@ int main(void) {
6
6
BTree x (" ./btree.dat" );
7
7
int32_t i;
8
8
9
- /*
10
9
for (i=0 ;i<1024 ;i++) {
11
10
x.Insert (i);
12
- }
13
- */
14
-
15
- for (i=0 ;i<1024 ;i++) {
16
11
int32_t r = x.Search (i);
17
12
printf (" idx[%d]\n " , r);
18
13
}
You can’t perform that action at this time.
0 commit comments