Skip to content

Commit

Permalink
Fix Pool to use a set internally
Browse files Browse the repository at this point in the history
  • Loading branch information
riannucci committed Mar 18, 2013
1 parent 72b3dae commit 8e70a53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/state.cc
Expand Up @@ -35,30 +35,39 @@ void Pool::EdgeFinished(const Edge& edge) {

void Pool::DelayEdge(Edge* edge) {
assert(depth_ != 0);
delayed_.push_back(edge);
delayed_.insert(edge);
}

void Pool::RetrieveReadyEdges(set<Edge*>* ready_queue) {
while (!delayed_.empty()) {
Edge* edge = delayed_.front();
set<Edge*>::iterator it = delayed_.begin();
while (it != delayed_.end()) {
Edge* edge = *it;
if (current_use_ + edge->weight() > depth_)
break;
delayed_.pop_front();
ready_queue->insert(edge);
EdgeScheduled(*edge);
++it;
}
delayed_.erase(delayed_.begin(), it);
}

void Pool::Dump() const {
printf("%s (%d/%d) ->\n", name_.c_str(), current_use_, depth_);
for (deque<Edge*>::const_iterator it = delayed_.begin();
for (set<Edge*>::const_iterator it = delayed_.begin();
it != delayed_.end(); ++it)
{
printf("\t");
(*it)->Dump();
}
}

bool Pool::WeightedEdgeCmp(const Edge* a, const Edge* b) {
if (!a) return b;
if (!b) return false;
int weight_diff = a->weight() - b->weight();
return ((weight_diff < 0) || (weight_diff == 0 && a < b));
}

Pool State::kDefaultPool("", 0);
const Rule State::kPhonyRule("phony");

Expand Down
6 changes: 4 additions & 2 deletions src/state.h
Expand Up @@ -39,7 +39,7 @@ struct Rule;
/// completes).
struct Pool {
explicit Pool(const string& name, int depth)
: name_(name), current_use_(0), depth_(depth) { }
: name_(name), current_use_(0), depth_(depth), delayed_(&WeightedEdgeCmp) { }

// A depth of 0 is infinite
bool is_valid() const { return depth_ >= 0; }
Expand Down Expand Up @@ -74,7 +74,9 @@ struct Pool {
int current_use_;
int depth_;

deque<Edge*> delayed_;
static bool WeightedEdgeCmp(const Edge* a, const Edge* b);

set<Edge*,bool(*)(const Edge*, const Edge*)> delayed_;
};

/// Global state (file status, loaded rules) for a single run.
Expand Down

0 comments on commit 8e70a53

Please sign in to comment.