Skip to content

fix(orama): fix AVLTree.removeNode path tracking when removing root - #1060

Open
EnesKartal wants to merge 1 commit into
oramasearch:mainfrom
EnesKartal:fix/1057-avl-root-remove
Open

EnesKartal wants to merge 1 commit into
oramasearch:mainfrom
EnesKartal:fix/1057-avl-root-remove

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #1057

Summary

  • Fixed AVLTree.removeNode in packages/orama/src/trees/avl.ts:
    • Removed the trailing path.push(current) after the 0/1-child and 2-child branches, which pushed the deleted root (for 0/1 children) or only successorParent (for 2 children) and caused the rebalance loop to overwrite node with the wrong root.
    • In the 2-child branch, pushed current and the intermediate nodes down to successorParent onto path so heights and balance are updated all the way back up to the root.
  • Added regression tests in packages/orama/tests/tree.avl.test.ts covering removing the AVL root with 0, 1, and 2 children.

Verification

  • npx tsc --noEmit in packages/orama: passed (0 errors).
  • npx tap tests/tree.avl.test.ts: 17/17 assertions passed.
  • npx tap tests/filters.test.ts: 54/54 assertions passed.
  • npx tap tests/remove.test.ts: 34/34 assertions passed (1 pre-existing skip).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remove() corrupts the number index when the key is at the AVL root; where filters return removed docs or miss live ones

1 participant