blob: f8d5afa7d8b95fc81835273f0631aa2c1569665c [file] [log] [blame]
Darin Petkov8e447e02013-04-16 16:23:50 +02001// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -08002// 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 Reyesb10320d2010-03-31 16:44:44 -070010#include <string>
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080011#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
19namespace chromeos_update_engine {
20
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070021bool operator==(const Extent& a, const Extent& b);
22
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080023struct EdgeProperties {
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070024 // 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;
Darin Petkov8e447e02013-04-16 16:23:50 +020028
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070029 // 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;
Darin Petkov8e447e02013-04-16 16:23:50 +020033
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070034 bool operator==(const EdgeProperties& that) const {
35 return extents == that.extents && write_extents == that.write_extents;
36 }
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080037};
38
39struct Vertex {
Darin Petkov8e447e02013-04-16 16:23:50 +020040 Vertex() :
41 valid(true),
42 index(-1),
43 lowlink(-1),
44 chunk_offset(0),
45 chunk_size(-1) {}
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070046 bool valid;
Darin Petkov8e447e02013-04-16 16:23:50 +020047
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080048 typedef std::map<std::vector<Vertex>::size_type, EdgeProperties> EdgeMap;
49 EdgeMap out_edges;
50
51 // We sometimes wish to consider a subgraph of a graph. A subgraph would have
52 // a subset of the vertices from the graph and a subset of the edges.
53 // When considering this vertex within a subgraph, subgraph_edges stores
54 // the out-edges.
55 typedef std::set<std::vector<Vertex>::size_type> SubgraphEdgeMap;
56 SubgraphEdgeMap subgraph_edges;
57
58 // For Tarjan's algorithm:
59 std::vector<Vertex>::size_type index;
60 std::vector<Vertex>::size_type lowlink;
61
62 // Other Vertex properties:
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070063 DeltaArchiveManifest_InstallOperation op;
64 std::string file_name;
Darin Petkov8e447e02013-04-16 16:23:50 +020065 off_t chunk_offset;
66 off_t chunk_size;
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080067
68 typedef std::vector<Vertex>::size_type Index;
69 static const Vertex::Index kInvalidIndex = -1;
70};
71
72typedef std::vector<Vertex> Graph;
73
74typedef std::pair<Vertex::Index, Vertex::Index> Edge;
75
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070076const uint64_t kSparseHole = kuint64max;
Andrew de los Reyes1bc16ab2010-10-06 15:07:21 -070077const uint64_t kTempBlockStart = 1ULL << 60;
78COMPILE_ASSERT(kTempBlockStart != 0, kTempBlockStart_invalid);
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070079
Andrew de los Reyes0ce161b2010-02-22 15:27:01 -080080} // namespace chromeos_update_engine
81
82#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__