-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
base: develop
Are you sure you want to change the base?
Add make_set function for DisjointSets #38692
Conversation
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.
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: |
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.
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: |
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.
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. |
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.
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] |
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.
why not using low level memcpy
method ?
This fixes #35599 by adding a
make_set
function toDisjointSet
usingOrbitPartitions
. The documentation links to wikipedia.From wikipedia, the method should be done in place and therefore there is no return
📝 Checklist
⌛ Dependencies
#35599