@@ -193,7 +193,20 @@ template <typename NodeID,
193
193
class QueryHeap
194
194
{
195
195
private:
196
- using HeapData = std::pair<Weight, Key>;
196
+ struct HeapData
197
+ {
198
+ Weight weight;
199
+ Key index;
200
+
201
+ bool operator >(const HeapData &other) const
202
+ {
203
+ if (weight == other.weight )
204
+ {
205
+ return index > other.index ;
206
+ }
207
+ return weight > other.weight ;
208
+ }
209
+ };
197
210
using HeapContainer = boost::heap::d_ary_heap<HeapData,
198
211
boost::heap::arity<4 >,
199
212
boost::heap::mutable_<true >,
@@ -232,7 +245,7 @@ class QueryHeap
232
245
{
233
246
BOOST_ASSERT (node < std::numeric_limits<NodeID>::max ());
234
247
const auto index = static_cast <Key>(inserted_nodes.size ());
235
- const auto handle = heap.push ( std::make_pair ( weight, index) );
248
+ const auto handle = heap.emplace (HeapData{ weight, index} );
236
249
inserted_nodes.emplace_back (HeapNode{handle, node, weight, data});
237
250
node_index[node] = index;
238
251
}
@@ -315,19 +328,19 @@ class QueryHeap
315
328
NodeID Min () const
316
329
{
317
330
BOOST_ASSERT (!heap.empty ());
318
- return inserted_nodes[heap.top ().second ].node ;
331
+ return inserted_nodes[heap.top ().index ].node ;
319
332
}
320
333
321
334
Weight MinKey () const
322
335
{
323
336
BOOST_ASSERT (!heap.empty ());
324
- return heap.top ().first ;
337
+ return heap.top ().weight ;
325
338
}
326
339
327
340
NodeID DeleteMin ()
328
341
{
329
342
BOOST_ASSERT (!heap.empty ());
330
- const Key removedIndex = heap.top ().second ;
343
+ const Key removedIndex = heap.top ().index ;
331
344
heap.pop ();
332
345
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator (heap.end ());
333
346
return inserted_nodes[removedIndex].node ;
@@ -336,7 +349,7 @@ class QueryHeap
336
349
HeapNode &DeleteMinGetHeapNode ()
337
350
{
338
351
BOOST_ASSERT (!heap.empty ());
339
- const Key removedIndex = heap.top ().second ;
352
+ const Key removedIndex = heap.top ().index ;
340
353
heap.pop ();
341
354
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator (heap.end ());
342
355
return inserted_nodes[removedIndex];
@@ -357,13 +370,13 @@ class QueryHeap
357
370
const auto index = node_index.peek_index (node);
358
371
auto &reference = inserted_nodes[index];
359
372
reference.weight = weight;
360
- heap.increase (reference.handle , std::make_pair ( weight, index));
373
+ heap.increase (reference.handle , HeapData{ weight, static_cast <Key>( index)} );
361
374
}
362
375
363
376
void DecreaseKey (const HeapNode &heapNode)
364
377
{
365
378
BOOST_ASSERT (!WasRemoved (heapNode.node ));
366
- heap.increase (heapNode.handle , std::make_pair ( heapNode.weight , (*heapNode.handle ).second ) );
379
+ heap.increase (heapNode.handle , HeapData{ heapNode.weight , (*heapNode.handle ).index } );
367
380
}
368
381
369
382
private:
0 commit comments