MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / fastRemove

Method fastRemove

src/common/classes/tree.h:549–628  ·  view source on GitHub ↗

Remove item. Current position moves to next item after this call. If next item doesn't exist method returns false

Source from the content-addressed store, hash-verified

547 // Remove item. Current position moves to next item after this call.
548 // If next item doesn't exist method returns false
549 bool fastRemove()
550 {
551 // invalidate current position of defaultAccessor
552 // if i'm not a defaultAccessor
553 if (this != &tree->defaultAccessor)
554 tree->defaultAccessor.curr = nullptr;
555
556 if (!tree->level)
557 {
558 this->curr->remove(this->curPos);
559 return this->curPos < this->curr->getCount();
560 }
561 if (this->curr->getCount() == 1)
562 {
563 // Only one node left in the current page. We cannot remove it directly
564 // because is would invalidate our tree structure
565 fb_assert(this->curPos == 0);
566 ItemList* temp;
567 if ((temp = this->curr->prev) && NEED_MERGE(temp->getCount(), LEAF_COUNT))
568 {
569 temp = this->curr->next;
570 tree->_removePage(0, this->curr);
571 this->curr = temp;
572 return this->curr;
573 }
574 if ((temp = this->curr->next) && NEED_MERGE(temp->getCount(), LEAF_COUNT))
575 {
576 tree->_removePage(0, this->curr);
577 this->curr = temp;
578 return true;
579 }
580 if ((temp = this->curr->prev))
581 {
582 (*this->curr)[0] = (*temp)[temp->getCount() - 1];
583 temp->shrink(temp->getCount() - 1);
584 this->curr = this->curr->next;
585 return this->curr;
586 }
587 if ((temp = this->curr->next))
588 {
589 (*this->curr)[0] = (*temp)[0];
590 temp->remove(0);
591 return true;
592 }
593 // It means the tree is broken
594 fb_assert(false);
595 return false;
596 }
597 this->curr->remove(this->curPos);
598 ItemList *temp;
599 if ((temp = this->curr->prev) &&
600 NEED_MERGE(temp->getCount() + this->curr->getCount(), LEAF_COUNT))
601 {
602 // After join upper levels of the tree remain stable because join doesn't change
603 // key of the page. The same applies to lower case too.
604 this->curPos += temp->getCount();
605 temp->join(*this->curr);
606 tree->_removePage(0, this->curr);

Callers

nothing calls this directly

Calls 6

NEED_MERGEFunction · 0.85
_removePageMethod · 0.80
removeMethod · 0.45
getCountMethod · 0.45
shrinkMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected