Skip to content
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

Add make_set function for DisjointSets #38692

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

thecaligarmo
Copy link
Contributor

This fixes #35599 by adding a make_set function to DisjointSet using OrbitPartitions. The documentation links to wikipedia.
From wikipedia, the method should be done in place and therefore there is no return

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

#35599

Copy link
Contributor

@dcoudert dcoudert 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 an interesting new functionality. However, why limiting to one extra element ?

cdef int *new_parent, *new_rank, *new_mcr, *new_size

cdef int *int_array = <int *> sig_malloc( 4*(n+1) * sizeof(int) )
if int_array is NULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really want to call free on NULL ?

new_rank = int_array + (n + 1)
new_mcr = int_array + (2*n + 2)
new_size = int_array + (3 * n + 3)
for i from 0 <= i < n:
Copy link
Contributor

Choose a reason for hiding this comment

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

for i in range(n)

@@ -834,6 +854,43 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
cdef int j = <int> self._el_to_int[f]
OP_join(self._nodes, i, j)

def make_set(self, new_elt = None):
r"""
Return a new disjoint set with an additional item.
Copy link
Contributor

Choose a reason for hiding this comment

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

You are not returning a new set, you are adding one new element to the set

new_size = int_array + (3 * n + 3)
for i from 0 <= i < n:
new_parent[i] = OP.parent[i]
new_rank[i] = OP.rank[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using low level memcpy method ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DisjointSet() misses MakeSet method
2 participants