- new_front_size = 0;
-
- for(int f = 0; f < front_size; f++) {
- v = _front[f];
- for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
- d = v->distance_from_source + e->positivized_length;
- tv = e->terminal_vertex;
- if(d < tv->distance_from_source) {
- tv->distance_from_source = d;
- tv->pred_edge_toward_source = e;
- if(tv->last_change < iteration) {
- _new_front[new_front_size++] = tv;
- tv->last_change = iteration;
- }
- }
+ // Get the closest to the source
+ v = _heap[0];
+
+ // Remove it from the heap (swap it with the last in the heap, and
+ // update the distance of that one)
+ _heap_size--;
+ a = _heap;
+ b = _heap + _heap_size;
+ swap(*a, *b); swap((*a)->heap_slot, (*b)->heap_slot);
+ increase_distance_in_heap(_heap[0]);
+
+ // Now update the neighbors of the currently closest to the source
+ for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
+ d = v->distance_from_source + e->positivized_length;
+ tv = e->terminal_vertex;
+ if(d < tv->distance_from_source) {
+ ASSERT(tv->heap_slot - _heap < _heap_size);
+ tv->distance_from_source = d;
+ tv->pred_edge_toward_source = e;
+ decrease_distance_in_heap(tv);