Skip to content

Conversation

@programmerjake
Copy link
Contributor

Adds UnionFind::new_set to add a new set to an existing UnionFind, which is helpful when you want to incrementally use the UnionFind algorithm and don't know how many elements you have ahead of time.

Fixes: #683

Also adds additional utility methods since UnionFind doesn't have fixed length anymore:

  • UnionFind::new_empty() -- equivalent to Vec::new() for when you need a const empty UnionFind.
  • UnionFind::is_empty()/UnionFind::len() -- returns the number of elements, like Vec::is_empty()/Vec::len()
  • impl Default for UnionFind -- makes an empty UnionFind

I also switched self.parent.len() calls to use self.len() since that's more canonical.

I also added a test checking that UnionFind::new_set() works correctly.

@programmerjake
Copy link
Contributor Author

programmerjake commented Jan 9, 2025

it's been a while and there have been multiple releases since I made this PR...can it be merged or do I need to make some changes? I have a crate that I want to publish a new version of eventually where one of the things it has been waiting on is this being merged and published to crates.io

Copy link
Member

@ABorgna ABorgna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

@ABorgna ABorgna merged commit ac86839 into petgraph:master Feb 1, 2025
6 checks passed
@starovoid starovoid removed this from the 0.8.3 milestone May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add methods to add new sets to UnionFind

4 participants