Skip to content

Commit 565196c

Browse files
committed
change priority queue into paring heap in shortest_path_to_set
1 parent 60dcb88 commit 565196c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/sage/graphs/base/c_graph.pyx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,16 +3698,15 @@ cdef class CGraphBackend(GenericGraphBackend):
36983698
exclude_vertices = set(exclude_vertices)
36993699
if source in exclude_vertices:
37003700
return
3701-
cdef priority_queue[pair[double, int]] pq
3701+
cdef PairingHeap[int, double] pq = PairingHeap[int, double]()
37023702
cdef dict dist = {}
37033703
cdef dict pred = {}
37043704
cdef int x_int = self.get_vertex(source)
3705-
pq.push((0, x_int))
3705+
pq.push(x_int, 0)
37063706
dist[x_int] = 0
37073707

37083708
while not pq.empty():
3709-
negative_d, v_int = pq.top()
3710-
d = -negative_d
3709+
v_int, d = pq.top()
37113710
pq.pop()
37123711
v = self.vertex_label(v_int)
37133712

@@ -3738,7 +3737,11 @@ cdef class CGraphBackend(GenericGraphBackend):
37383737
if new_dist < dist.get(u_int, float('inf')):
37393738
dist[u_int] = new_dist
37403739
pred[u_int] = v_int
3741-
pq.push((-new_dist, u_int))
3740+
if pq.contains(u_int):
3741+
if pq.value(u_int) > new_dist:
3742+
pq.decrease(u_int, new_dist)
3743+
else:
3744+
pq.push(u_int, new_dist)
37423745

37433746
return
37443747

0 commit comments

Comments
 (0)