| 216 | |
| 217 | |
| 218 | bool remove(Target target, unsigned shift) { |
| 219 | assert_precondition(shift + kBitShift < 8*sizeof(hash_t)); |
| 220 | unsigned bitNo = childBitNumber(target.hash, shift); |
| 221 | if (!hasChild(bitNo)) |
| 222 | return false; |
| 223 | unsigned childIndex = childIndexForBitNumber(bitNo); |
| 224 | NodeRef childRef = _children[childIndex]; |
| 225 | if (childRef.isLeaf()) { |
| 226 | // Child is a leaf -- is it the right key? |
| 227 | if (childRef.matches(target)) { |
| 228 | removeChild(bitNo, childIndex); |
| 229 | delete (MutableLeaf*)childRef.asMutable(); |
| 230 | return true; |
| 231 | } else { |
| 232 | return false; |
| 233 | } |
| 234 | } else { |
| 235 | // Recurse into child node... |
| 236 | auto child = (MutableInterior*)childRef.asMutable(); |
| 237 | if (child) { |
| 238 | if (!child->remove(target, shift+kBitShift)) |
| 239 | return false; |
| 240 | } else { |
| 241 | child = mutableCopy(&childRef.asImmutable()->interior); |
| 242 | if (!child->remove(target, shift+kBitShift)) { |
| 243 | delete child; |
| 244 | return false; |
| 245 | } |
| 246 | _children[childIndex] = child; |
| 247 | } |
| 248 | if (child->_bitmap.empty()) { |
| 249 | removeChild(bitNo, childIndex); // child node is now empty, so remove it |
| 250 | delete child; |
| 251 | } |
| 252 | return true; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | |
| 257 | static offset_t encodeImmutableOffset(const Node *inode, offset_t off, const Encoder &enc) { |
nothing calls this directly
no test coverage detected