diff options
author | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-11 00:15:50 +0200 |
---|---|---|
committer | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-11 00:15:50 +0200 |
commit | 180bcc4e3daac6262fcb7eb2bc337eb4eed44be0 (patch) | |
tree | a5d64d0f15d970ea182070f3a8ca0a81df2e74fb /planning/planning.cpp | |
parent | 45005d52aa5679961082087ffe38376a29e075a5 (diff) |
More function splitting in planning.
Diffstat (limited to 'planning/planning.cpp')
-rw-r--r-- | planning/planning.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/planning/planning.cpp b/planning/planning.cpp index 5c621a1..ba8994f 100644 --- a/planning/planning.cpp +++ b/planning/planning.cpp @@ -463,6 +463,25 @@ end: logprintf("Augmented using %d paths.\n", num_paths); } +// Figure out which distro this switch was connected to. +int find_distro(const Graph &g, int switch_index) +{ + for (unsigned j = 0; j < NUM_DISTRO; ++j) { + Edge *flow_edge = NULL; + for (unsigned k = 0; k < g.distro_nodes[j].edges.size(); ++k) { + Edge *e = g.distro_nodes[j].edges[k]; + if (e->to == &g.switch_nodes[switch_index]) { + flow_edge = e; + break; + } + } + if (flow_edge != NULL && flow_edge->flow > 0) { + return j; + } + } + return -1; +} + int Planner::do_work(int distro_placements[NUM_DISTRO]) { memcpy(this->distro_placements, distro_placements, sizeof(distro_placements[0]) * NUM_DISTRO); @@ -489,23 +508,7 @@ int Planner::do_work(int distro_placements[NUM_DISTRO]) in_addr_t subnet_address = inet_addr(FIRST_SUBNET_ADDRESS); #endif for (unsigned i = 0; i < switches.size(); ++i) { - // Figure out which distro this switch was connected to. - int distro = -1; - for (unsigned j = 0; j < NUM_DISTRO; ++j) { - Edge *flow_edge = NULL; - for (unsigned k = 0; k < g.distro_nodes[j].edges.size(); ++k) { - Edge *e = g.distro_nodes[j].edges[k]; - if (e->to == &g.switch_nodes[i]) { - flow_edge = e; - break; - } - } - if (flow_edge != NULL && flow_edge->flow > 0) { - distro = j; - break; - } - } - + int distro = find_distro(g, i); if (i == 0 || switches[i].row != switches[i - 1].row) { if (last_row == 5 || last_row == 13 || last_row == 21 || last_row == 29) { logprintf("\n"); |