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

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: Changed server_position to server_ordinal in DB 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 00:57:59 hmm why is this necessary? Why not CreateInitialO
vishwath 2012/10/05 18:34:49 There are multiple places where new entry kernels
rlarocque 2012/10/05 19:02:55 I think the trend is to initialize those values in
vishwath 2012/10/05 21:05:48 Entrykernels are also created in directory_backing
akalin 2012/10/05 21:20:15 Yeah. Ideally, EntryKernels would have to be cons
rlarocque 2012/10/05 21:29:34 I think I agree, but I just want to clarify. Entr
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 const Ordinal<Traits>& rhs) const { 225 const Ordinal<Traits>& rhs) const {
226 return lhs.Equals(rhs); 226 return lhs.Equals(rhs);
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()
236 : bytes_(Traits::kMinLength, kZeroDigit),
237 is_valid_(true){
238 bytes_[0] = kMidDigit;
239 }
236 240
237 template <typename Traits> 241 template <typename Traits>
238 Ordinal<Traits> Ordinal<Traits>::CreateInitialOrdinal() { 242 Ordinal<Traits> Ordinal<Traits>::CreateInitialOrdinal() {
239 std::string bytes(Traits::kMinLength, kZeroDigit); 243 std::string bytes(Traits::kMinLength, kZeroDigit);
240 bytes[0] = kMidDigit; 244 bytes[0] = kMidDigit;
241 return Ordinal(bytes); 245 return Ordinal(bytes);
242 } 246 }
243 247
244 template <typename Traits> 248 template <typename Traits>
245 bool Ordinal<Traits>::IsValid() const { 249 bool Ordinal<Traits>::IsValid() const {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 DCHECK_LT(midpoint, end_bytes); 481 DCHECK_LT(midpoint, end_bytes);
478 482
479 Ordinal<Traits> midpoint_ordinal(midpoint); 483 Ordinal<Traits> midpoint_ordinal(midpoint);
480 DCHECK(midpoint_ordinal.IsValid()); 484 DCHECK(midpoint_ordinal.IsValid());
481 return midpoint_ordinal; 485 return midpoint_ordinal;
482 } 486 }
483 487
484 } // namespace syncer 488 } // namespace syncer
485 489
486 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ 490 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698