mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
@josephsavona had the intuition that we were picking the wrong root in the previous infinite loop test case, so the fix for this is to force a root to always be picked. This works because `find` implements path compression (if a <- b and b <- c, then we can just point a <- c to "flatten" the tree which makes subsequent `find` operations more efficient since we don't have to follow the ancestor chain each time), so we're forcing all those unions to pick one parent. From some googling it looks like the traditional way to implement union is to call `find` so this should be the "right" way to fix it (?). I'm also adding a basic unit test for DisjointSet, I think we could revisit later and see if property testing is worth it but for now I mainly wanted to capture the regression test as a unit test.