Allow to store references and eventually delete them
make-github-pseudonymous-again opened this issue · 3 comments
make-github-pseudonymous-again commented
const node = tree.add(x);
...
tree.unlink(node);
This is currently not possible because, among other potential problems, rotations swap keys of references to save operations.
make-github-pseudonymous-again commented
According to the command rg '\.key.*=.*\.key'
, the only other place where this happens is in RedBlackTree#_delete
.
make-github-pseudonymous-again commented
Note that this requires keeping track of the RedBlackTree#root
in all these operations.
make-github-pseudonymous-again commented
PS: We could have used a WeakMap
to point to the current node even though keys have been swapped. But this could lead to a two-fold increase of space usage because it prevents garbage collection of unlinked nodes whose keys has been swapped at some point.