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

Side by Side Diff: components/sync/base/node_ordinal.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « components/sync/base/nigori_unittest.cc ('k') | components/sync/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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_NODE_ORDINAL_H_ 5 #ifndef COMPONENTS_SYNC_BASE_NODE_ORDINAL_H_
6 #define SYNC_INTERNAL_API_PUBLIC_BASE_NODE_ORDINAL_H_ 6 #define COMPONENTS_SYNC_BASE_NODE_ORDINAL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "sync/base/sync_export.h" 11 #include "components/sync/base/ordinal.h"
12 #include "sync/internal_api/public/base/ordinal.h" 12 #include "components/sync/base/sync_export.h"
13 13
14 namespace syncer { 14 namespace syncer {
15 15
16 // A NodeOrdinal is an Ordinal whose internal value comes from the 16 // A NodeOrdinal is an Ordinal whose internal value comes from the
17 // ordinal_in_parent field of SyncEntity (see sync.proto). It uses 17 // ordinal_in_parent field of SyncEntity (see sync.proto). It uses
18 // the entire uint8_t range for backwards compatibility with the old 18 // the entire uint8_t range for backwards compatibility with the old
19 // int64_t-based positioning. 19 // int64_t-based positioning.
20 20
21 struct NodeOrdinalTraits { 21 struct NodeOrdinalTraits {
22 static const uint8_t kZeroDigit = 0; 22 static const uint8_t kZeroDigit = 0;
23 static const uint8_t kMaxDigit = UINT8_MAX; 23 static const uint8_t kMaxDigit = UINT8_MAX;
24 static const size_t kMinLength = 8; 24 static const size_t kMinLength = 8;
25 }; 25 };
26 26
27 typedef Ordinal<NodeOrdinalTraits> NodeOrdinal; 27 typedef Ordinal<NodeOrdinalTraits> NodeOrdinal;
28 28
29 static_assert(static_cast<char>(NodeOrdinal::kZeroDigit) == '\x00', 29 static_assert(static_cast<char>(NodeOrdinal::kZeroDigit) == '\x00',
30 "NodeOrdinal has incorrect zero digit"); 30 "NodeOrdinal has incorrect zero digit");
31 static_assert(static_cast<char>(NodeOrdinal::kOneDigit) == '\x01', 31 static_assert(static_cast<char>(NodeOrdinal::kOneDigit) == '\x01',
32 "NodeOrdinal has incorrect one digit"); 32 "NodeOrdinal has incorrect one digit");
33 static_assert(static_cast<char>(NodeOrdinal::kMidDigit) == '\x80', 33 static_assert(static_cast<char>(NodeOrdinal::kMidDigit) == '\x80',
34 "NodeOrdinal has incorrect mid digit"); 34 "NodeOrdinal has incorrect mid digit");
35 static_assert(static_cast<char>(NodeOrdinal::kMaxDigit) == '\xff', 35 static_assert(static_cast<char>(NodeOrdinal::kMaxDigit) == '\xff',
36 "NodeOrdinal has incorrect max digit"); 36 "NodeOrdinal has incorrect max digit");
37 static_assert(NodeOrdinal::kMidDigitValue == 128, 37 static_assert(NodeOrdinal::kMidDigitValue == 128,
38 "NodeOrdinal has incorrect mid digit value"); 38 "NodeOrdinal has incorrect mid digit value");
39 static_assert(NodeOrdinal::kMaxDigitValue == 255, 39 static_assert(NodeOrdinal::kMaxDigitValue == 255,
40 "NodeOrdinal has incorrect max digit value"); 40 "NodeOrdinal has incorrect max digit value");
41 static_assert(NodeOrdinal::kRadix == 256, 41 static_assert(NodeOrdinal::kRadix == 256, "NodeOrdinal has incorrect radix");
42 "NodeOrdinal has incorrect radix");
43 42
44 // Converts an int64_t position (usually from the position_in_parent 43 // Converts an int64_t position (usually from the position_in_parent
45 // field of SyncEntity) to a NodeOrdinal. This transformation 44 // field of SyncEntity) to a NodeOrdinal. This transformation
46 // preserves the ordering relation: a < b under integer ordering if 45 // preserves the ordering relation: a < b under integer ordering if
47 // and only if Int64ToNodeOrdinal(a) < Int64ToNodeOrdinal(b). 46 // and only if Int64ToNodeOrdinal(a) < Int64ToNodeOrdinal(b).
48 SYNC_EXPORT NodeOrdinal Int64ToNodeOrdinal(int64_t x); 47 SYNC_EXPORT NodeOrdinal Int64ToNodeOrdinal(int64_t x);
49 48
50 // The inverse of Int64ToNodeOrdinal. This conversion is, in general, 49 // The inverse of Int64ToNodeOrdinal. This conversion is, in general,
51 // lossy: NodeOrdinals can have arbitrary fidelity, while numeric 50 // lossy: NodeOrdinals can have arbitrary fidelity, while numeric
52 // positions contain only 64 bits of information (in fact, this is the 51 // positions contain only 64 bits of information (in fact, this is the
53 // reason we've moved away from them). 52 // reason we've moved away from them).
54 SYNC_EXPORT int64_t NodeOrdinalToInt64(const NodeOrdinal& ordinal); 53 SYNC_EXPORT int64_t NodeOrdinalToInt64(const NodeOrdinal& ordinal);
55 54
56 } // namespace syncer 55 } // namespace syncer
57 56
58 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_NODE_ORDINAL_H_ 57 #endif // COMPONENTS_SYNC_BASE_NODE_ORDINAL_H_
OLDNEW
« no previous file with comments | « components/sync/base/nigori_unittest.cc ('k') | components/sync/base/node_ordinal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698