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

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

Issue 10920017: [Sync] Generalize StringOrdinal to handle ordinal_in_parent field (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Relax tests Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « sync/api/string_ordinal.h ('k') | sync/internal_api/public/base/node_ordinal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_NODE_ORDINAL_H_
6 #define SYNC_INTERNAL_API_PUBLIC_BASE_NODE_ORDINAL_H_
7
8 #include "base/basictypes.h"
9 #include "sync/internal_api/public/base/ordinal.h"
10
11 namespace syncer {
12
13 // A NodeOrdinal is an Ordinal whose internal value comes from the
14 // ordinal_in_parent field of SyncEntity (see sync.proto). It uses
15 // the entire uint8 range for backwards compatibility with the old
16 // int64-based positioning.
17
18 struct NodeOrdinalTraits {
19 static const uint8 kZeroDigit = 0;
20 static const uint8 kMaxDigit = kuint8max;
21 static const size_t kMinLength = 8;
22 };
23
24 typedef Ordinal<NodeOrdinalTraits> NodeOrdinal;
25
26 COMPILE_ASSERT(static_cast<char>(NodeOrdinal::kZeroDigit) == '\x00',
27 NodeOrdinalHasCorrectZeroDigit);
28 COMPILE_ASSERT(static_cast<char>(NodeOrdinal::kOneDigit) == '\x01',
29 NodeOrdinalHasCorrectOneDigit);
30 COMPILE_ASSERT(static_cast<char>(NodeOrdinal::kMidDigit) == '\x80',
31 NodeOrdinalHasCorrectMidDigit);
32 COMPILE_ASSERT(static_cast<char>(NodeOrdinal::kMaxDigit) == '\xff',
33 NodeOrdinalHasCorrectMaxDigit);
34 COMPILE_ASSERT(NodeOrdinal::kMidDigitValue == 128,
35 NodeOrdinalHasCorrectMidDigitValue);
36 COMPILE_ASSERT(NodeOrdinal::kMaxDigitValue == 255,
37 NodeOrdinalHasCorrectMaxDigitValue);
38 COMPILE_ASSERT(NodeOrdinal::kRadix == 256,
39 NodeOrdinalHasCorrectRadix);
40
41 // Converts an int64 position (usually from the position_in_parent
42 // field of SyncEntity) to a NodeOrdinal. This transformation
43 // preserves the ordering relation: a < b under integer ordering if
44 // and only if Int64ToNodeOrdinal(a) < Int64ToNodeOrdinal(b).
45 NodeOrdinal Int64ToNodeOrdinal(int64 x);
46
47 // The inverse of Int64ToNodeOrdinal. This conversion is, in general,
48 // lossy: NodeOrdinals can have arbitrary fidelity, while numeric
49 // positions contain only 64 bits of information (in fact, this is the
50 // reason we've moved away from them).
51 int64 NodeOrdinalToInt64(const NodeOrdinal& ordinal);
52
53 } // namespace syncer
54
55 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_NODE_ORDINAL_H_
OLDNEW
« no previous file with comments | « sync/api/string_ordinal.h ('k') | sync/internal_api/public/base/node_ordinal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698