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 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <set> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 10 | #include <string> |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | #include "base/basictypes.h" |
| 14 | #include "update_engine/update_metadata.pb.h" |
| 15 | |
| 16 | // A few classes that help in generating delta images use these types |
| 17 | // for the graph work. |
| 18 | |
| 19 | namespace chromeos_update_engine { |
| 20 | |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame^] | 21 | bool operator==(const Extent& a, const Extent& b); |
| 22 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 23 | struct EdgeProperties { |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame^] | 24 | // Read-before extents. I.e., blocks in |extents| must be read by the |
| 25 | // node pointed to before the pointing node runs (presumably b/c it |
| 26 | // overwrites these blocks). |
| 27 | std::vector<Extent> extents; |
| 28 | |
| 29 | // Write before extents. I.e., blocks in |write_extents| must be written |
| 30 | // by the node pointed to before the pointing node runs (presumably |
| 31 | // b/c it reads the data written by the other node). |
| 32 | std::vector<Extent> write_extents; |
| 33 | |
| 34 | bool operator==(const EdgeProperties& that) const { |
| 35 | return extents == that.extents && write_extents == that.write_extents; |
| 36 | } |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct Vertex { |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame^] | 40 | Vertex() : valid(true), index(-1), lowlink(-1) {} |
| 41 | bool valid; |
| 42 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 43 | typedef std::map<std::vector<Vertex>::size_type, EdgeProperties> EdgeMap; |
| 44 | EdgeMap out_edges; |
| 45 | |
| 46 | // We sometimes wish to consider a subgraph of a graph. A subgraph would have |
| 47 | // a subset of the vertices from the graph and a subset of the edges. |
| 48 | // When considering this vertex within a subgraph, subgraph_edges stores |
| 49 | // the out-edges. |
| 50 | typedef std::set<std::vector<Vertex>::size_type> SubgraphEdgeMap; |
| 51 | SubgraphEdgeMap subgraph_edges; |
| 52 | |
| 53 | // For Tarjan's algorithm: |
| 54 | std::vector<Vertex>::size_type index; |
| 55 | std::vector<Vertex>::size_type lowlink; |
| 56 | |
| 57 | // Other Vertex properties: |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 58 | DeltaArchiveManifest_InstallOperation op; |
| 59 | std::string file_name; |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 60 | |
| 61 | typedef std::vector<Vertex>::size_type Index; |
| 62 | static const Vertex::Index kInvalidIndex = -1; |
| 63 | }; |
| 64 | |
| 65 | typedef std::vector<Vertex> Graph; |
| 66 | |
| 67 | typedef std::pair<Vertex::Index, Vertex::Index> Edge; |
| 68 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 69 | const uint64_t kSparseHole = kuint64max; |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame^] | 70 | const uint64_t kTempBlockStart = 1ULL << 60; |
| 71 | COMPILE_ASSERT(kTempBlockStart != 0, kTempBlockStart_invalid); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 72 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 73 | } // namespace chromeos_update_engine |
| 74 | |
| 75 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |