* NAME: node->free() * DESCRIPTION: deallocate and remove a b*-tree node */
| 102 | * DESCRIPTION: deallocate and remove a b*-tree node |
| 103 | */ |
| 104 | int n_free(node *np) |
| 105 | { |
| 106 | btree *bt = np->bt; |
| 107 | node sib; |
| 108 | |
| 109 | if (bt->hdr.bthFNode == np->nnum) |
| 110 | bt->hdr.bthFNode = np->nd.ndFLink; |
| 111 | |
| 112 | if (bt->hdr.bthLNode == np->nnum) |
| 113 | bt->hdr.bthLNode = np->nd.ndBLink; |
| 114 | |
| 115 | if (np->nd.ndFLink > 0) |
| 116 | { |
| 117 | if (bt_getnode(&sib, bt, np->nd.ndFLink) == -1) |
| 118 | goto fail; |
| 119 | |
| 120 | sib.nd.ndBLink = np->nd.ndBLink; |
| 121 | |
| 122 | if (bt_putnode(&sib) == -1) |
| 123 | goto fail; |
| 124 | } |
| 125 | |
| 126 | if (np->nd.ndBLink > 0) |
| 127 | { |
| 128 | if (bt_getnode(&sib, bt, np->nd.ndBLink) == -1) |
| 129 | goto fail; |
| 130 | |
| 131 | sib.nd.ndFLink = np->nd.ndFLink; |
| 132 | |
| 133 | if (bt_putnode(&sib) == -1) |
| 134 | goto fail; |
| 135 | } |
| 136 | |
| 137 | BMCLR(bt->map, np->nnum); |
| 138 | ++bt->hdr.bthFree; |
| 139 | |
| 140 | bt->flags |= HFS_BT_UPDATE_HDR; |
| 141 | |
| 142 | return 0; |
| 143 | |
| 144 | fail: |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * NAME: compact() |
no test coverage detected