Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: cycle_breaker.cc

Issue 3015023: AU: delta generation: cut cycles in graph more aggressively (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cycle_breaker.h ('k') | cycle_breaker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cycle_breaker.cc
diff --git a/cycle_breaker.cc b/cycle_breaker.cc
index 6e0689891f615f8d7f220e38f707629c0664a353..2f14767e808d9ef229f7a266b6488f0f29b29338 100644
--- a/cycle_breaker.cc
+++ b/cycle_breaker.cc
@@ -77,6 +77,8 @@ void CycleBreaker::HandleCircuit() {
CHECK_GE(stack_.size(), 2);
Edge min_edge = make_pair(stack_[0], stack_[1]);
uint64_t min_edge_weight = kuint64max;
+ const int kMaxEdgesToConsider = 4;
+ int edges_considered = 0;
for (vector<Vertex::Index>::const_iterator it = stack_.begin();
it != (stack_.end() - 1); ++it) {
Edge edge = make_pair(*it, *(it + 1));
@@ -89,6 +91,9 @@ void CycleBreaker::HandleCircuit() {
min_edge_weight = edge_weight;
min_edge = edge;
}
+ edges_considered++;
+ if (edges_considered == kMaxEdgesToConsider)
+ break;
}
cut_edges_.insert(min_edge);
stack_.pop_back();
@@ -106,6 +111,17 @@ void CycleBreaker::Unblock(Vertex::Index u) {
}
}
+bool CycleBreaker::StackContainsCutEdge() const {
+ for (std::vector<Vertex::Index>::const_iterator it = ++stack_.begin(),
+ e = stack_.end(); it != e; ++it) {
+ Edge edge = make_pair(*(it - 1), *it);
+ if (utils::SetContainsKey(cut_edges_, edge)) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool CycleBreaker::Circuit(Vertex::Index vertex) {
// "vertex" was "v" in the original paper.
bool found = false; // Was "f" in the original paper.
@@ -122,8 +138,11 @@ bool CycleBreaker::Circuit(Vertex::Index vertex) {
HandleCircuit();
found = true;
} else if (!blocked_[*w]) {
- if (Circuit(*w))
+ if (Circuit(*w)) {
found = true;
+ if (StackContainsCutEdge())
petkov 2010/07/23 06:32:23 this seems to introduce n^2 kind of complexity...
+ break;
+ }
}
}
« no previous file with comments | « cycle_breaker.h ('k') | cycle_breaker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698