Skip to content

Commit

Permalink
micro-optimization for Kruskal's algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Dell'Amico committed Jan 29, 2018
1 parent 5125346 commit 8a80782
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flexible_clustering/fishdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ def update_mst(self):
# Kruskal's algorithm
self._mst_edges = mst_edges = []
n = len(self.data)
needed_edges = n - 1
uf = UnionFind(n)
n_edges = 0
while n_edges < n - 1:
while needed_edges:
_, i, j, _ = edge = heapq.heappop(candidate_edges)
if uf.union(i, j):
mst_edges.append(edge)
n_edges += 1
needed_edges -= 1

new_edges.clear()

def cluster(self, min_cluster_size=None, cluster_selection_method='eom',
Expand Down

0 comments on commit 8a80782

Please sign in to comment.