OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <string> | 10 #include <string> |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Constants for Ordinal digits. | 134 // Constants for Ordinal digits. |
135 static const uint8 kZeroDigit = Traits::kZeroDigit; | 135 static const uint8 kZeroDigit = Traits::kZeroDigit; |
136 static const uint8 kMaxDigit = Traits::kMaxDigit; | 136 static const uint8 kMaxDigit = Traits::kMaxDigit; |
137 static const size_t kMinLength = Traits::kMinLength; | 137 static const size_t kMinLength = Traits::kMinLength; |
138 static const uint8 kOneDigit = kZeroDigit + 1; | 138 static const uint8 kOneDigit = kZeroDigit + 1; |
139 static const uint8 kMidDigit = kOneDigit + (kMaxDigit - kOneDigit) / 2; | 139 static const uint8 kMidDigit = kOneDigit + (kMaxDigit - kOneDigit) / 2; |
140 static const unsigned int kMidDigitValue = kMidDigit - kZeroDigit; | 140 static const unsigned int kMidDigitValue = kMidDigit - kZeroDigit; |
141 static const unsigned int kMaxDigitValue = kMaxDigit - kZeroDigit; | 141 static const unsigned int kMaxDigitValue = kMaxDigit - kZeroDigit; |
142 static const unsigned int kRadix = kMaxDigitValue + 1; | 142 static const unsigned int kRadix = kMaxDigitValue + 1; |
143 | 143 |
144 COMPILE_ASSERT(kOneDigit > kZeroDigit, OrdinalOneDigitGreaterThanMinDigit); | 144 static_assert(kOneDigit > kZeroDigit, "incorrect ordinal one digit"); |
145 COMPILE_ASSERT(kMidDigit > kOneDigit, OrdinalMidDigitGreaterThanOneDigit); | 145 static_assert(kMidDigit > kOneDigit, "incorrect ordinal mid digit"); |
146 COMPILE_ASSERT(kMaxDigit > kMidDigit, OrdinalMaxDigitGreaterThanMidDigit); | 146 static_assert(kMaxDigit > kMidDigit, "incorrect ordinal max digit"); |
147 COMPILE_ASSERT(kMinLength > 0, OrdinalMinLengthIsPositive); | 147 static_assert(kMinLength > 0, "incorrect ordinal min length"); |
148 COMPILE_ASSERT(kMidDigitValue > 1, OrdinalMidDigitValueGreaterThanOne); | 148 static_assert(kMidDigitValue > 1, "incorrect ordinal mid digit"); |
149 COMPILE_ASSERT(kMaxDigitValue > kMidDigitValue, | 149 static_assert(kMaxDigitValue > kMidDigitValue, "incorrect ordinal max digit"); |
150 OrdinalMaxDigitValueGreaterThanMidDigitValue); | 150 static_assert(kRadix == kMaxDigitValue + 1, "incorrect ordinal radix"); |
151 COMPILE_ASSERT(kRadix == kMaxDigitValue + 1, | |
152 OrdinalRadixIsMaxDigitValuePlusOne); | |
153 | 151 |
154 private: | 152 private: |
155 // Returns true iff the given byte string satisfies the criteria for | 153 // Returns true iff the given byte string satisfies the criteria for |
156 // a valid Ordinal. | 154 // a valid Ordinal. |
157 static bool IsValidOrdinalBytes(const std::string& bytes); | 155 static bool IsValidOrdinalBytes(const std::string& bytes); |
158 | 156 |
159 // Returns the length that bytes.substr(0, length) would be with | 157 // Returns the length that bytes.substr(0, length) would be with |
160 // trailing zero digits removed. | 158 // trailing zero digits removed. |
161 static size_t GetLengthWithoutTrailingZeroDigits( | 159 static size_t GetLengthWithoutTrailingZeroDigits( |
162 const std::string& bytes, | 160 const std::string& bytes, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 DCHECK_LT(midpoint, end_bytes); | 475 DCHECK_LT(midpoint, end_bytes); |
478 | 476 |
479 Ordinal<Traits> midpoint_ordinal(midpoint); | 477 Ordinal<Traits> midpoint_ordinal(midpoint); |
480 DCHECK(midpoint_ordinal.IsValid()); | 478 DCHECK(midpoint_ordinal.IsValid()); |
481 return midpoint_ordinal; | 479 return midpoint_ordinal; |
482 } | 480 } |
483 | 481 |
484 } // namespace syncer | 482 } // namespace syncer |
485 | 483 |
486 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ | 484 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ |
OLD | NEW |