* NAME: node->new() * DESCRIPTION: allocate a new b*-tree node */
| 70 | * DESCRIPTION: allocate a new b*-tree node |
| 71 | */ |
| 72 | int n_new(node *np) |
| 73 | { |
| 74 | btree *bt = np->bt; |
| 75 | unsigned long num; |
| 76 | |
| 77 | if (bt->hdr.bthFree == 0) |
| 78 | ERROR(EIO, "b*-tree full"); |
| 79 | |
| 80 | num = 0; |
| 81 | while (num < bt->hdr.bthNNodes && BMTST(bt->map, num)) |
| 82 | ++num; |
| 83 | |
| 84 | if (num == bt->hdr.bthNNodes) |
| 85 | ERROR(EIO, "free b*-tree node not found"); |
| 86 | |
| 87 | np->nnum = num; |
| 88 | |
| 89 | BMSET(bt->map, num); |
| 90 | --bt->hdr.bthFree; |
| 91 | |
| 92 | bt->flags |= HFS_BT_UPDATE_HDR; |
| 93 | |
| 94 | return 0; |
| 95 | |
| 96 | fail: |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * NAME: node->free() |