Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS 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_RANGES_H__ | |
|
petkov
2010/10/05 05:56:26
CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_RANGES_H__
adlr
2010/10/05 17:47:59
Done.
| |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_RANGES_H__ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include <base/basictypes.h> | |
| 13 | |
| 14 #include "update_engine/delta_diff_generator.h" | |
| 15 #include "update_engine/graph_types.h" | |
| 16 #include "update_engine/update_metadata.pb.h" | |
| 17 | |
| 18 // An ExtentRanges object represents an unordered collection of extents | |
| 19 // (and therefore blocks). Such an object may be modified by adding or | |
| 20 // subtracting blocks (think: set addition or set subtraction). | |
| 21 | |
| 22 namespace chromeos_update_engine { | |
| 23 | |
| 24 struct ExtentLess | |
| 25 { | |
|
petkov
2010/10/05 05:56:26
move { to the previous line
adlr
2010/10/05 17:47:59
Done.
| |
| 26 bool operator()(const Extent& x, const Extent& y) const { | |
| 27 return x.start_block() < y.start_block(); | |
| 28 } | |
| 29 }; | |
| 30 | |
| 31 Extent ExtentForRange(uint64_t start_block, uint64_t num_blocks); | |
| 32 | |
| 33 class ExtentRanges { | |
| 34 public: | |
| 35 typedef std::set<Extent, ExtentLess> ExtentSet; | |
| 36 | |
| 37 ExtentRanges() : blocks_(0) {} | |
| 38 void AddBlock(uint64_t block); | |
| 39 void SubtractBlock(uint64_t block); | |
| 40 void AddExtent(Extent extent); | |
| 41 void SubtractExtent(const Extent& extent); | |
| 42 void AddExtents(const std::vector<Extent>& extents); | |
| 43 void SubtractExtents(const std::vector<Extent>& extents); | |
| 44 void AddRepeatedExtents( | |
| 45 const ::google::protobuf::RepeatedPtrField<Extent> &exts); | |
| 46 void SubtractRepeatedExtents( | |
| 47 const ::google::protobuf::RepeatedPtrField<Extent> &exts); | |
| 48 void AddRanges(const ExtentRanges& ranges); | |
| 49 void SubtractRanges(const ExtentRanges& ranges); | |
| 50 | |
| 51 static bool ExtentsOverlapOrTouch(const Extent& a, const Extent& b); | |
| 52 static bool ExtentsOverlap(const Extent& a, const Extent& b); | |
| 53 | |
| 54 // Dumps contents to the log file. Useful for debugging. | |
| 55 void Dump() const; | |
| 56 | |
| 57 uint64_t blocks() const { return blocks_; } | |
| 58 const ExtentSet& extent_set() const { return extent_set_; } | |
| 59 | |
| 60 // Returns an ordered vector of extents for |count| blocks, | |
| 61 // using extents in extent_set_. The returned extents are not | |
| 62 // removed from extent_set_. |count| must be less than or equal to | |
| 63 // the number of blocks in this extent set. | |
| 64 std::vector<Extent> GetExtentsForBlockCount(uint64_t count) const; | |
| 65 | |
| 66 private: | |
| 67 ExtentSet extent_set_; | |
| 68 uint64_t blocks_; | |
| 69 }; | |
| 70 | |
| 71 } // namespace chromeos_update_engine | |
| 72 | |
| 73 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_RANGES_H__ | |
| OLD | NEW |