MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / split

Function split

dep/hfsutils/libhfs/node.c:251–340  ·  view source on GitHub ↗

* NAME: split() * DESCRIPTION: divide a node into two and insert a record */

Source from the content-addressed store, hash-verified

249 * DESCRIPTION: divide a node into two and insert a record
250 */
251static
252int split(node *left, byte *record, unsigned int *reclen)
253{
254 btree *bt = left->bt;
255 node n, *right = &n, *side = 0;
256 int mark, i;
257
258 /* create a second node by cloning the first */
259
260 *right = *left;
261
262 if (n_new(right) == -1)
263 goto fail;
264
265 left->nd.ndFLink = right->nnum;
266 right->nd.ndBLink = left->nnum;
267
268 /* divide all records evenly between the two nodes */
269
270 mark = (NODEUSED(*left) + 2 * left->nd.ndNRecs + *reclen + 2) >> 1;
271
272 if (left->rnum == -1)
273 {
274 side = left;
275 mark -= *reclen + 2;
276 }
277
278 for (i = 0; i < left->nd.ndNRecs; ++i)
279 {
280 node *np;
281 byte *rec;
282
283 np = (mark > 0) ? right : left;
284 rec = HFS_NODEREC(*np, i);
285
286 mark -= HFS_RECLEN(*np, i) + 2;
287
288 HFS_SETKEYLEN(rec, 0);
289
290 if (left->rnum == i)
291 {
292 side = (mark > 0) ? left : right;
293 mark -= *reclen + 2;
294 }
295 }
296
297 compact(left);
298 compact(right);
299
300 /* insert the new record and store the modified nodes */
301
302 ASSERT(side);
303
304 n_search(side, record);
305 n_insertx(side, record, *reclen);
306
307 if (bt_putnode(left) == -1 ||
308 bt_putnode(right) == -1)

Callers 1

n_insertFunction · 0.70

Calls 7

n_newFunction · 0.85
compactFunction · 0.85
n_searchFunction · 0.85
n_insertxFunction · 0.85
bt_putnodeFunction · 0.85
n_indexFunction · 0.85
bt_getnodeFunction · 0.85

Tested by

no test coverage detected