X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mtp.git;a=blobdiff_plain;f=mtp_graph.cc;h=6c97c5d09e207c831416b15880e8a67273946dd6;hp=33d5a4ff0d8bdd191467b5cdaf8fc607108fb5a3;hb=ecead8ae3e8f3fdc43f6f8b2d7327e253cdae637;hpb=86c860c0f43a9130e4121072620961fc892ed83f diff --git a/mtp_graph.cc b/mtp_graph.cc index 33d5a4f..6c97c5d 100644 --- a/mtp_graph.cc +++ b/mtp_graph.cc @@ -110,20 +110,21 @@ void Vertex::increase_distance_in_heap(Vertex **heap, int heap_size) { Vertex **c1, **c2, **h; // omg, that's beautiful h = heap_slot; - while(c1 = heap + 2 * (h - heap + 1) - 1, c2 = c1 + 1, - (c1 < heap + heap_size && (*c1)->distance_from_source < (*h)->distance_from_source) - || - (c2 < heap + heap_size && (*c2)->distance_from_source < (*h)->distance_from_source) - ) { - if(c1 < heap + heap_size && - !(c2 < heap + heap_size && (*c2)->distance_from_source < (*c1)->distance_from_source)){ - swap(*c1, *h); - swap((*c1)->heap_slot, (*h)->heap_slot); - h = c1; - } else { + while(c1 = heap + 2 * (h - heap) + 1, + c1 < heap + heap_size && + (c2 = c1 + 1, + (*c1)->distance_from_source < (*h)->distance_from_source + || + (c2 < heap + heap_size && (*c2)->distance_from_source < (*h)->distance_from_source) + )) { + if(c2 < heap + heap_size && (*c2)->distance_from_source <= (*c1)->distance_from_source) { swap(*c2, *h); swap((*c2)->heap_slot, (*h)->heap_slot); h = c2; + } else { + swap(*c1, *h); + swap((*c1)->heap_slot, (*h)->heap_slot); + h = c1; } } }