Skip to content

Commit 6334550

Browse files
use HLPQ set instead of add for existing heap elements
1 parent 2c58f34 commit 6334550

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

alpha/alpha-algo/src/main/java/org/neo4j/gds/impl/spanningtree/KSpanningTree.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ private SpanningTree growApproach(SpanningTree spanningTree) {
281281
}
282282
}
283283
if (affectedNode != -1) { //if a node has been converted to a leaf
284-
toTrim.add(affectedNode, affectedCost); //add it to pq
284+
if (!toTrim.containsElement(affectedNode)) {
285+
toTrim.add(affectedNode, affectedCost); //add it to pq
286+
} else {
287+
//it is still in the queue, but it is not a leaf anymore, so it's value is obsolete
288+
toTrim.set(affectedNode, affectedCost);
289+
}
285290
exterior.set(affectedNode); //and mark it in the exterior
286291
}
287292
} else {
@@ -373,7 +378,7 @@ private SpanningTree combineApproach(SpanningTree tree) {
373378
}
374379
var spanningTree1 = cutLeafApproach(tree);
375380
var spanningTree2 = growApproach(tree);
376-
381+
System.out.println("Prune Leaf: " + spanningTree1.totalWeight() + " Grow Mst:" + spanningTree2.totalWeight());
377382
if (spanningTree1.totalWeight() > spanningTree2.totalWeight()) {
378383
return (minMax == Prim.MAX_OPERATOR) ? spanningTree1 : spanningTree2;
379384
} else {

0 commit comments

Comments
 (0)