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

Faster union find #415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions hdbscan/_hdbscan_linkage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,20 @@ cdef class UnionFind (object):
self.size[self.next_label] = self.size[m] + self.size[n]
self.parent[m] = self.next_label
self.parent[n] = self.next_label
self.size[self.next_label] = self.size[m] + self.size[n]
self.next_label += 1

return

cdef np.intp_t fast_find(self, np.intp_t n):
cdef np.intp_t p
cdef np.intp_t p, tmp
p = n
while self.parent_arr[n] != -1:
n = self.parent_arr[n]
# label up to the root
while self.parent_arr[p] != n:
p, self.parent_arr[p] = self.parent_arr[p], n
while self.parent[n] != -1:
n = self.parent[n]
# label up to the root if this is not the root already
if p != n:
while self.parent[p] != n:
tmp = self.parent[p]
self.parent[p] = n
p = tmp
return n


Expand Down