Skip to content

Commit

Permalink
Fix heap corruption in union find
Browse files Browse the repository at this point in the history
  • Loading branch information
markopy committed Feb 10, 2020
1 parent bce8dae commit 1a5a81f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions hdbscan/_hdbscan_linkage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,18 @@ 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
p = n
while self.parent[n] != -1:
n = self.parent[n]
# label up to the root
while self.parent[p] != n:
p, self.parent[p] = self.parent[p], n
# label up to the root if this is not the root already
if p != n:
while self.parent[p] != n:
p, self.parent[p] = self.parent[p], n
return n


Expand Down

0 comments on commit 1a5a81f

Please sign in to comment.