find(key) not working
Closed this issue · 1 comments
MatanelGordon commented
I've tried the following code taken from the docs:
const t = new AVLTree();
t.load([3,2,-10,20], ['C', 'B', 'A', 'D']);
On top of it I added that piece of code at the end:
[-10,20,2,3].map(x => t.find(x))
result : [{…}, {…}, null, null]
I'm pretty positive that's not the wanted output. Am I doing something wrong? Or is it a real problem?
Either way, I can implement such search function on my own, but I'm just curious to know why it's not working
w8r commented
Hi! The problem is my documentation. By default, the keys and values are not sorted when you bulk-load.
If you provide a boolean flag for sorting as the third parameter, it works fine. https://runkit.com/embed/doqe2g51fs4r
I will update the docs