Skip to content

Commit a20e8e9

Browse files
committed
src: Only add OptimizedArrayQueueSet element if unique
1 parent cdd42af commit a20e8e9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/graphs/shortestpaths/SPFASolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public SPFASolver(Graph<V> graph, V start) {
3737
if (newDist < oldDist) {
3838
edgeTo.put(to, e);
3939
distTo.put(to, newDist);
40-
if (!queue.contains(to)) {
41-
queue.add(to);
42-
}
40+
queue.add(to);
4341
}
4442
}
4543
}
@@ -90,6 +88,9 @@ public Iterator<E> iterator() {
9088

9189
@Override
9290
public boolean offer(E e) {
91+
if (set.contains(e)) {
92+
return false;
93+
}
9394
boolean result = queue.offer(e);
9495
set.add(e);
9596
return result;

0 commit comments

Comments
 (0)