Improved union-find data structure implementation #412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch makes several bugfixes and improvements to the union-find data
structure implemented by the BoruvkaUnionFind class:
(1) union_() did not update is_component. If it merged two components
and no subsequent find() operation updated is_component, then
components() would report an incorrect result.
(2) Formerly, union_() did not recognize when it was passed two objects
in the same set. In this case, it would improperly increment the set's
rank. As a result, later calls to union_() sometimes produced unbalanced
trees, degrading performance.
(3) The path compression algorithm in find() has been replaced by Tarjan
and Van Leeuwen's path splitting algorithm. Path splitting has the same
asymptotic performance as path compression, but it has better constant
factors because it requires only one pass through the tree.
(4) The parent pointer tree and the ranks have been separated into
different arrays. This improves memory locality because parent pointers
are accessed much more frequently than the ranks of the nodes.
(5) Ranks are now stored in a single byte, decreasing memory usage and
again improving memory locality. Ranks are bounded above by
floor(log2(size)), so one byte is plenty (...for now).