-
Notifications
You must be signed in to change notification settings - Fork 247
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
path compression variants for union-find IntDisjointSet #913
base: master
Are you sure you want to change the base?
Conversation
Here are benchmark times for a
I'm using:
|
println("Recursive may path compression may encounter stack-overflow; skipping") | ||
else | ||
s = create_disjoint_set_struct(n) | ||
@btime find_root!($s, $n, PCRecursive()) |
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.
increase the number of evals to let's say 100. post the median and max time. do it for all of the methods
return current | ||
end | ||
|
||
# path-splitting: every node on the path points to its grandparent |
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.
what's the exact difference between path compression using path halving and path splitting? it's not very clear. can you illustrate with an example?
root = current | ||
# compress the path: make every node point directly to the root | ||
current = x | ||
@inbounds while parents[current] != root |
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.
address the test coverage warning.
end | ||
|
||
|
||
struct PCRecursive end # path compression types |
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.
make this an enum.
@@ -68,6 +68,7 @@ module DataStructures | |||
include("queue.jl") | |||
include("accumulator.jl") | |||
include("disjoint_set.jl") | |||
export PCRecursive, PCIterative, PCHalving, PCSplitting |
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.
after making it an enum, export the enum
Thanks for reviewing @eulerkochy! I'll address when I have a chance (next week). Also, wanted to draw your attention to a concurrent implementation: https://github.com/kalmarek/ConcurrentDisjointSets.jl |
Based on a question I'd asked on Discourse, I received some encouragement to write a path-halving/path-splitting implementation for union-find data structure. I have a first draft of this for consideration. This was also related to 911.