Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/graph_utils.h" |
| 6 | #include "base/basictypes.h" |
| 7 | |
| 8 | using std::vector; |
| 9 | |
| 10 | namespace chromeos_update_engine { |
| 11 | |
| 12 | namespace graph_utils { |
| 13 | |
| 14 | uint64 EdgeWeight(const Graph& graph, const Edge& edge) { |
| 15 | uint64 weight = 0; |
| 16 | const vector<Extent>& extents = |
| 17 | graph[edge.first].out_edges.find(edge.second)->second.extents; |
| 18 | for (vector<Extent>::const_iterator it = extents.begin(); |
| 19 | it != extents.end(); ++it) { |
| 20 | weight += it->num_blocks(); |
| 21 | } |
| 22 | return weight; |
| 23 | } |
| 24 | |
| 25 | void AppendBlockToExtents(vector<Extent>* extents, uint64 block) { |
| 26 | if (!extents->empty()) { |
| 27 | Extent& extent = extents->back(); |
| 28 | if (extent.start_block() + extent.num_blocks() == block) { |
| 29 | extent.set_num_blocks(extent.num_blocks() + 1); |
| 30 | return; |
| 31 | } |
| 32 | } |
| 33 | Extent new_extent; |
| 34 | new_extent.set_start_block(block); |
| 35 | new_extent.set_num_blocks(1); |
| 36 | extents->push_back(new_extent); |
| 37 | } |
| 38 | |
| 39 | } // namespace graph_utils |
| 40 | |
| 41 | } // namespace chromeos_update_engine |