summaryrefslogtreecommitdiffstats
path: root/otautil/rangeset.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-08-28 19:09:13 +0200
committerTao Bao <tbao@google.com>2018-08-28 19:49:07 +0200
commit43bfa6e429d650ca94e69d170f872079ba76534a (patch)
tree8b40951fec00af3b937baf52cd4dbf6563634065 /otautil/rangeset.cpp
parentMerge "Remove otafault" (diff)
downloadandroid_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar.gz
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar.bz2
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar.lz
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar.xz
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.tar.zst
android_bootable_recovery-43bfa6e429d650ca94e69d170f872079ba76534a.zip
Diffstat (limited to '')
-rw-r--r--otautil/rangeset.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/otautil/rangeset.cpp b/otautil/rangeset.cpp
index 96955b9d0..5ab8e08fe 100644
--- a/otautil/rangeset.cpp
+++ b/otautil/rangeset.cpp
@@ -148,8 +148,8 @@ std::string RangeSet::ToString() const {
return "";
}
std::string result = std::to_string(ranges_.size() * 2);
- for (const auto& r : ranges_) {
- result += android::base::StringPrintf(",%zu,%zu", r.first, r.second);
+ for (const auto& [begin, end] : ranges_) {
+ result += android::base::StringPrintf(",%zu,%zu", begin, end);
}
return result;
@@ -159,11 +159,11 @@ std::string RangeSet::ToString() const {
size_t RangeSet::GetBlockNumber(size_t idx) const {
CHECK_LT(idx, blocks_) << "Out of bound index " << idx << " (total blocks: " << blocks_ << ")";
- for (const auto& range : ranges_) {
- if (idx < range.second - range.first) {
- return range.first + idx;
+ for (const auto& [begin, end] : ranges_) {
+ if (idx < end - begin) {
+ return begin + idx;
}
- idx -= (range.second - range.first);
+ idx -= (end - begin);
}
CHECK(false) << "Failed to find block number for index " << idx;
@@ -173,14 +173,10 @@ size_t RangeSet::GetBlockNumber(size_t idx) const {
// RangeSet has half-closed half-open bounds. For example, "3,5" contains blocks 3 and 4. So "3,5"
// and "5,7" are not overlapped.
bool RangeSet::Overlaps(const RangeSet& other) const {
- for (const auto& range : ranges_) {
- size_t start = range.first;
- size_t end = range.second;
- for (const auto& other_range : other.ranges_) {
- size_t other_start = other_range.first;
- size_t other_end = other_range.second;
- // [start, end) vs [other_start, other_end)
- if (!(other_start >= end || start >= other_end)) {
+ for (const auto& [begin, end] : ranges_) {
+ for (const auto& [other_begin, other_end] : other.ranges_) {
+ // [begin, end) vs [other_begin, other_end)
+ if (!(other_begin >= end || begin >= other_end)) {
return true;
}
}
@@ -248,20 +244,20 @@ bool SortedRangeSet::Overlaps(size_t start, size_t len) const {
size_t SortedRangeSet::GetOffsetInRangeSet(size_t old_offset) const {
size_t old_block_start = old_offset / kBlockSize;
size_t new_block_start = 0;
- for (const auto& range : ranges_) {
+ for (const auto& [start, end] : ranges_) {
// Find the index of old_block_start.
- if (old_block_start >= range.second) {
- new_block_start += (range.second - range.first);
- } else if (old_block_start >= range.first) {
- new_block_start += (old_block_start - range.first);
+ if (old_block_start >= end) {
+ new_block_start += (end - start);
+ } else if (old_block_start >= start) {
+ new_block_start += (old_block_start - start);
return (new_block_start * kBlockSize + old_offset % kBlockSize);
} else {
CHECK(false) << "block_start " << old_block_start
- << " is missing between two ranges: " << this->ToString();
+ << " is missing between two ranges: " << ToString();
return 0;
}
}
CHECK(false) << "block_start " << old_block_start
- << " exceeds the limit of current RangeSet: " << this->ToString();
+ << " exceeds the limit of current RangeSet: " << ToString();
return 0;
}