Skip to content

Commit aff5ebc

Browse files
committed
Pool: sort equally-weighted edges by priority
1 parent 4c9f289 commit aff5ebc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/graph.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,14 @@ struct DependencyScan {
384384
DyndepLoader dyndep_loader_;
385385
};
386386

387-
// Implements a less comarison for edges by priority, where highest
387+
// Implements a less comparison for edges by priority, where highest
388388
// priority is defined lexicographically first by largest critical
389389
// time, then lowest ID.
390390
//
391391
// Including ID means that wherever the critical times are the same,
392392
// the edges are executed in ascending ID order which was historically
393393
// how all tasks were scheduled.
394-
struct EdgePriorityCompare {
394+
struct EdgePriorityLess {
395395
bool operator()(const Edge* e1, const Edge* e2) const {
396396
const int64_t ct1 = e1->critical_time();
397397
const int64_t ct2 = e2->critical_time();
@@ -402,11 +402,18 @@ struct EdgePriorityCompare {
402402
}
403403
};
404404

405+
// Reverse of EdgePriorityLess, e.g. to sort by highest priority first
406+
struct EdgePriorityGreater {
407+
bool operator()(const Edge* e1, const Edge* e2) const {
408+
return EdgePriorityLess()(e2, e1);
409+
}
410+
};
411+
405412
// A priority queue holding non-owning Edge pointers. top() will
406413
// return the edge with the largest critical time, and lowest ID if
407414
// more than one edge has the same critical time.
408415
class EdgePriorityQueue:
409-
public std::priority_queue<Edge*, std::vector<Edge*>, EdgePriorityCompare>{
416+
public std::priority_queue<Edge*, std::vector<Edge*>, EdgePriorityLess>{
410417
public:
411418
void clear() {
412419
c.clear();

src/state.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ struct Pool {
8080
if (!a) return b;
8181
if (!b) return false;
8282
int weight_diff = a->weight() - b->weight();
83-
return ((weight_diff < 0) || (weight_diff == 0 && EdgeCmp()(a, b)));
83+
if (weight_diff != 0) {
84+
return weight_diff < 0;
85+
}
86+
return EdgePriorityGreater()(a, b);
8487
}
8588
};
8689

0 commit comments

Comments
 (0)