-
Notifications
You must be signed in to change notification settings - Fork 262
For DisjointSets, make union! return the root of the newly merged set #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| # merge the subset containing x and that containing y into one | ||
| # | ||
| function union!(s::IntDisjointSets, x::Integer, y::Integer) | ||
| parents = s.parents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick reply. I think parents is used in find_root_impl! below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, sorry, I don't know how I missed that.
|
I think that makes sense and is a reasonable change. This can be merged after addressing the inline comments. |
|
A couple of more (quick) requests: Please
|
|
@kmsquire all the requests are addressed. Please let me know if you have any other comments. |
README.rst
Outdated
| Note that the internal implementation of ``IntDisjointSets`` is based on vectors, and is very efficient. ``DisjointSets{T}`` is a wrapper of ``IntDisjointSets``, which uses a dictionary to map input elements to an internal index. | ||
| Note that the internal implementation of ``IntDisjointSets`` is based on vectors, and is very efficient. ``DisjointSets{T}`` is a wrapper of ``IntDisjointSets``, which uses a dictionary to map input elements to an internal index. | ||
| As a result, ``union!(a, "a", "b")`` and ``root_union!(a, "a", "d")`` returns the indices of the | ||
| root elements rather than the root elements themselves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering...
- Is there a way to go from index to element?
- If someone is manipulating non-integer
DisjointSets, is returning the resulting index is useful? Can they use that index in further processing? How?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to go from index to element?
Since DisjointSets use a dictionary to wrap IntDisjointSets, "to go from index to element" means get a key by value in a dictionary. This is doable but not very efficient, perhaps something like
for (key, value) in intmap
if value == index
return key
end
endWe may add a new field to DisjointSets, but this is a major change and shoud be considered in a different pull request. By the way, currently find_root only returns the index of the root rather than the root itself.
If someone is manipulating non-integer DisjointSets, is returning the resulting index is useful? Can they use that index in further processing? How?
Yes, the index can be used in further processing. Just use the simple example from the documentation.
> list = ["a", "b", "c", "d"]
> a = DisjointSets{AbstractString}(list)
> indx = union!(a, "a", "b")
> list[indx]
"a"|
@weijianzhang, sorry, I was about to merge, but it looks like something else snuck in that caused a merge conflict (probably in the exports). Can you rebase on the current master? After that, I thing this is mergable. |
|
@kmsquire sure, no problem. I will fix the conflicts. Thanks. |
|
(Thanks... and can you squash those please?) |
|
Hi @kmsquire, sorry but I don't know how. I can only squash consecutive commits but there are a few commits between my last commit and this commit. I've made a few attempts but was unsuccessful. Could you let me know how I can do this? |
|
Hi @weijianzhang, if you run it should move your commits to the most recent position. From there, you should be able to squash and force push to this branch. If that doesn't work for some reason, just post back here and we'll figure something out. |
|
@weijianzhang Looks like you merged the current master, instead of rebasing. Rebasing re-writes history as if your changes came after. Here's one way to fix: You will need to fix the README conflicts here (simple, remove all the stuff on the bottom). I wouldn't bother adding the doc changes, since we can retrieve those from the merge you already did. When you're done Take a look at what you're missing (from the merge you already did) Apply those changes Add your missing changes: Amend them (add them) to your last commit (which should now, be your first commit) If everything looks right now, you should be able to push this to your remote. |
|
@kmsquire @DanielArndt Thanks a lot for your help. I think it is fixed now. |
|
Great! The history looks a lot cleaner now. |
For DisjointSets, make union! return the root of the newly merged set
|
@kmsquire should we bump the version to v0.4.3 now that these recent changes have been merged in? |
|
Yep. Can you? |
|
Sure, will do so tonight |
For
DisjointSets, it is useful ifunion!can return the root of the newly merged set.For example, it is used in implementing elimination tree for sparse factorization.
(See Algorithm 5.1 of [2])
The implementation of
_union!is based on [1].After this merge, we have
References:
[1] Data Structures and Network Algorithms, Robert Tarjan (1983) Chapter 2
Disjoint Sets [url]
[2] The Role of Elimination Trees in Sparse Factorization, Joseph W.H. Liu [url]