llrb.js – Remove Gets Values Mixed Up
Thanks for this project. Good stuff. I noticed one small defect, which has a quick fix:
There is a minor typo in llrb.js, in the remove(h, key, compare) method, line 111 currently, where it uses “val”, instead of “value”. This results in the value of the removed node being retained, and the value of another node being lost. Easy fix: just change the two instances of “val” on that line to “value”. Seems to work great after that.
Thanks for reporting it. Yeah, if you look at the rest of the code in that file it's obvious it's just a typo.
FYI I re-implemented llrb.js here with a lot of improvements: https://github.com/AndrewDavis/LLRB-Binary-Search-Tree-JS
I noticed a slight discrepancy between llrb.js and the original Java code it pulls from in that its moveRedLeft() and moveRedRight() functions are each missing a flipColors() call, see here: https://github.com/AndrewDavis/LLRB-Binary-Search-Tree-JS/commit/502a059936dadc634d6c11be2e9869f10d311253#diff-8ff9488676c6c98d65322afd0ad49cd7R491
I'm not sure, but I believe this doesn't break it but maybe it runs a little faster? Just FYI.