From a552a55cce5516ace081f86d9d5def9da25876a8 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 17 May 2022 11:56:51 +0200 Subject: [PATCH] Follow-up to f5ec76c2300095f23af6be9d37488b7f434df25d Compile-time instantiation of the MutablePriorityQueue with run-time resetting of indices when removing items from the queue active in debug mode only. --- src/libslic3r/ShortestPath.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/ShortestPath.cpp b/src/libslic3r/ShortestPath.cpp index 449ff45b5..72bfe1f30 100644 --- a/src/libslic3r/ShortestPath.cpp +++ b/src/libslic3r/ShortestPath.cpp @@ -195,7 +195,15 @@ std::vector> chain_segments_greedy_constrained_reversals } // Initialize a heap of end points sorted by the lowest distance to the next valid point of a path. - auto queue = make_mutable_priority_queue( + auto queue = make_mutable_priority_queue( [](EndPoint *ep, size_t idx){ ep->heap_idx = idx; }, [](EndPoint *l, EndPoint *r){ return l->distance_out < r->distance_out; }); queue.reserve(end_points.size() * 2 - 1); @@ -213,7 +221,7 @@ std::vector> chain_segments_greedy_constrained_reversals assert(ep.chain_id == 0); } else { // End point is NOT on the heap, therefore it is part of the output path. - assert(ep.heap_idx == std::numeric_limits::max()); + assert(ep.heap_idx == queue.invalid_id()); assert(ep.chain_id != 0); if (&ep == first_point) { assert(ep.edge_out == nullptr); @@ -222,7 +230,7 @@ std::vector> chain_segments_greedy_constrained_reversals // Detect loops. for (EndPoint *pt = &ep; pt != nullptr;) { // Out of queue. It is a final point. - assert(pt->heap_idx == std::numeric_limits::max()); + assert(pt->heap_idx == queue.invalid_id()); EndPoint *pt_other = &end_points[(pt - &end_points.front()) ^ 1]; if (pt_other->heap_idx < queue.size()) // The other side of this segment is undecided yet.