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

Function n_delete

dep/hfsutils/libhfs/node.c:427–473  ·  view source on GitHub ↗

* NAME: node->delete() * DESCRIPTION: remove a record from a node */

Source from the content-addressed store, hash-verified

425 * DESCRIPTION: remove a record from a node
426 */
427int n_delete(node *np, byte *record, int *flag)
428{
429 byte *rec;
430
431 rec = HFS_NODEREC(*np, np->rnum);
432
433 HFS_SETKEYLEN(rec, 0);
434 compact(np);
435
436 if (np->nd.ndNRecs == 0)
437 {
438 if (n_free(np) == -1)
439 goto fail;
440
441 HFS_SETKEYLEN(record, 0);
442 *flag = 1;
443
444 return 0;
445 }
446
447 /* see if we can join with our left sibling */
448
449 if (np->nd.ndBLink > 0)
450 {
451 node left;
452
453 if (bt_getnode(&left, np->bt, np->nd.ndBLink) == -1)
454 goto fail;
455
456 if (np->nd.ndNRecs + left.nd.ndNRecs <= HFS_MAX_NRECS &&
457 NODEUSED(*np) + 2 * np->nd.ndNRecs <= NODEFREE(left))
458 return join(&left, np, record, flag);
459 }
460
461 if (np->rnum == 0)
462 {
463 /* special case: first record changed; update parent record key */
464
465 n_index(np, record, 0);
466 *flag = 1;
467 }
468
469 return bt_putnode(np);
470
471fail:
472 return -1;
473}

Callers 1

deletexFunction · 0.85

Calls 6

compactFunction · 0.85
n_freeFunction · 0.85
bt_getnodeFunction · 0.85
n_indexFunction · 0.85
bt_putnodeFunction · 0.85
joinFunction · 0.70

Tested by

no test coverage detected