askorama / orama

🌌 Fast, dependency-free, full-text and vector search engine with typo tolerance, filters, facets, stemming, and more. Works with any JavaScript runtime, browser, server, service!

Home Page:https://docs.orama.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unbalances balanced avl tree

allevo opened this issue · comments

Describe the bug

When the results are already sorted, the avl tree is not balanced at all.

To Reproduce

  const numbers = [
      [ 7288, 0.4166666666666667 ],
      [ 19172, 0.4791666666666667 ],
      [ 5025, 0.5526315789473685 ],
      [ 9148, 0.5625 ],
      [ 10806, 0.6097560975609756 ]
    ]
    const tree = create(0, [])
    for (const [id, number] of numbers) {
      insert(tree, number, [id])
    }
    console.log(JSON.stringify(tree, null, 2))
    console.log('isBalanced', isBalanced(tree))
  })

Expected behavior

The tree should be balanced.

Environment Info

node: v20.8.1

Affected areas

Data Insertion

Additional context

No response