You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The RedBlackTree.from() method creates a shallow copy of the original tree. When a node is removed from the copied tree, it inadvertently corrupts the original tree, leading to unexpected behavior.
Steps to Reproduce
Create a RedBlackTree with the values [3, 10, 13, 4, 6, 7, 1, 14].
Use RedBlackTree.from() to create a copy of the original tree without providing a custom compare or map function.
Remove the value 7 from the copied tree.
Attempt to find the value 7 in the original tree.
Expected behavior
Removing a node from the copied tree should not affect the original tree. The original tree should still contain the value 7 after the removal operation on the copy.
Deno.test("RedBlackTree.from() bug demo - removing in copy corrupts original",()=>{// 1. Build the original treeconstvalues=[3,10,13,4,6,7,1,14];constoriginal=RedBlackTree.from(values);// original should have 8 elements and include 7// 2. Create a copy without passing compare/mapconstcopy=RedBlackTree.from(original);// copy and original should be independent trees// 3. Remove value 7 from the copyconstremovedInCopy=7;constremoveResult=copy.remove(removedInCopy);// If all is well, removing 7 from copy should not affect original// 4. Original tree should still find 7conststillInOriginal=original.find(removedInCopy);// Assertion: original should still contain 7assertStrictEquals(stillInOriginal!==null,true,`Expected original.find(${removedInCopy}) to not be null, but got null.`);// Additionally, check if removeResult is trueassertStrictEquals(removeResult,true,`Expected copy.remove(${removedInCopy}) to return true, but got false.`);});
The text was updated successfully, but these errors were encountered:
Describe the bug
The
RedBlackTree.from()
method creates a shallow copy of the original tree. When a node is removed from the copied tree, it inadvertently corrupts the original tree, leading to unexpected behavior.Steps to Reproduce
[3, 10, 13, 4, 6, 7, 1, 14]
.RedBlackTree.from()
to create a copy of the original tree without providing a customcompare
ormap
function.7
from the copied tree.7
in the original tree.Expected behavior
Removing a node from the copied tree should not affect the original tree. The original tree should still contain the value
7
after the removal operation on the copy.Environment
Test Case
The text was updated successfully, but these errors were encountered: