MCPcopy Create free account
hub / github.com/couchbase/fleece / remove

Method remove

Fleece/Tree/MutableNode.hh:218–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 5

asImmutableMethod · 0.80
isLeafMethod · 0.45
matchesMethod · 0.45
asMutableMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected