Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: sync/internal_api/public/base/ordinal.h

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Ordinal default ctor now creates invalid Ordinals Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 EqualsFn(); 71 EqualsFn();
72 72
73 bool operator()(const Ordinal<Traits>& lhs, 73 bool operator()(const Ordinal<Traits>& lhs,
74 const Ordinal<Traits>& rhs) const; 74 const Ordinal<Traits>& rhs) const;
75 }; 75 };
76 76
77 // Creates an Ordinal from the given string of bytes. The Ordinal 77 // Creates an Ordinal from the given string of bytes. The Ordinal
78 // may be valid or invalid. 78 // may be valid or invalid.
79 explicit Ordinal(const std::string& bytes); 79 explicit Ordinal(const std::string& bytes);
80 80
81 // Creates an invalid Ordinal. 81 // Creates a valid initial Ordinal.
akalin 2012/10/05 22:40:27 revert this
vishwath 2012/10/08 20:17:49 Done.
82 Ordinal(); 82 Ordinal();
83 83
84 // Creates a valid initial Ordinal. This is called to create the first 84 // Creates a valid initial Ordinal. This is called to create the first
85 // element of Ordinal list (i.e. before we have any other values we can 85 // element of Ordinal list (i.e. before we have any other values we can
86 // generate from). 86 // generate from).
87 static Ordinal CreateInitialOrdinal(); 87 static Ordinal CreateInitialOrdinal();
88 88
89 // Returns true iff this Ordinal is valid. This takes constant 89 // Returns true iff this Ordinal is valid. This takes constant
90 // time. 90 // time.
91 bool IsValid() const; 91 bool IsValid() const;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 template <typename Traits> 229 template <typename Traits>
230 Ordinal<Traits>::Ordinal(const std::string& bytes) 230 Ordinal<Traits>::Ordinal(const std::string& bytes)
231 : bytes_(bytes), 231 : bytes_(bytes),
232 is_valid_(IsValidOrdinalBytes(bytes_)) {} 232 is_valid_(IsValidOrdinalBytes(bytes_)) {}
233 233
234 template <typename Traits> 234 template <typename Traits>
235 Ordinal<Traits>::Ordinal() : is_valid_(false) {} 235 Ordinal<Traits>::Ordinal() : is_valid_(false) {}
236 236
237 //template <typename Traits>
akalin 2012/10/05 22:40:27 remove this
vishwath 2012/10/08 20:17:49 Done.
238 //Ordinal<Traits>::Ordinal()
239 // : bytes_(Traits::kMinLength, kZeroDigit),
240 // is_valid_(true){
241 // bytes_[0] = kMidDigit;
242 //}
243
237 template <typename Traits> 244 template <typename Traits>
238 Ordinal<Traits> Ordinal<Traits>::CreateInitialOrdinal() { 245 Ordinal<Traits> Ordinal<Traits>::CreateInitialOrdinal() {
239 std::string bytes(Traits::kMinLength, kZeroDigit); 246 std::string bytes(Traits::kMinLength, kZeroDigit);
240 bytes[0] = kMidDigit; 247 bytes[0] = kMidDigit;
241 return Ordinal(bytes); 248 return Ordinal(bytes);
242 } 249 }
243 250
244 template <typename Traits> 251 template <typename Traits>
245 bool Ordinal<Traits>::IsValid() const { 252 bool Ordinal<Traits>::IsValid() const {
246 DCHECK_EQ(IsValidOrdinalBytes(bytes_), is_valid_); 253 DCHECK_EQ(IsValidOrdinalBytes(bytes_), is_valid_);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 DCHECK_LT(midpoint, end_bytes); 484 DCHECK_LT(midpoint, end_bytes);
478 485
479 Ordinal<Traits> midpoint_ordinal(midpoint); 486 Ordinal<Traits> midpoint_ordinal(midpoint);
480 DCHECK(midpoint_ordinal.IsValid()); 487 DCHECK(midpoint_ordinal.IsValid());
481 return midpoint_ordinal; 488 return midpoint_ordinal;
482 } 489 }
483 490
484 } // namespace syncer 491 } // namespace syncer
485 492
486 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ 493 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698