@fluid-experimental/tree 2.118.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +22 -4
  2. package/README.md +52 -48
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -6
  4. package/api-extractor/api-extractor-report.json +9 -0
  5. package/dist/ChangeCompression.js +4 -3
  6. package/dist/ChangeCompression.js.map +1 -1
  7. package/dist/ChangeTypes.d.ts.map +1 -1
  8. package/dist/Checkout.js +28 -1
  9. package/dist/Checkout.js.map +1 -1
  10. package/dist/Common.js +27 -27
  11. package/dist/Common.js.map +1 -1
  12. package/dist/EditLog.d.ts.map +1 -1
  13. package/dist/EditLog.js +15 -11
  14. package/dist/EditLog.js.map +1 -1
  15. package/dist/EditUtilities.js +18 -18
  16. package/dist/EditUtilities.js.map +1 -1
  17. package/dist/Forest.js +12 -3
  18. package/dist/Forest.js.map +1 -1
  19. package/dist/HistoryEditFactory.js +2 -2
  20. package/dist/HistoryEditFactory.js.map +1 -1
  21. package/dist/IdConversion.js +4 -5
  22. package/dist/IdConversion.js.map +1 -1
  23. package/dist/Identifiers.js +1 -2
  24. package/dist/Identifiers.js.map +1 -1
  25. package/dist/LazyCheckout.js +1 -0
  26. package/dist/LazyCheckout.js.map +1 -1
  27. package/dist/LogViewer.js +50 -16
  28. package/dist/LogViewer.js.map +1 -1
  29. package/dist/MergeHealth.js +121 -123
  30. package/dist/MergeHealth.js.map +1 -1
  31. package/dist/NodeIdUtilities.js +4 -5
  32. package/dist/NodeIdUtilities.js.map +1 -1
  33. package/dist/PayloadUtilities.js +1 -2
  34. package/dist/PayloadUtilities.js.map +1 -1
  35. package/dist/RevisionValueCache.js +18 -6
  36. package/dist/RevisionValueCache.js.map +1 -1
  37. package/dist/RevisionView.js +3 -3
  38. package/dist/RevisionView.js.map +1 -1
  39. package/dist/SerializationUtilities.js +4 -5
  40. package/dist/SerializationUtilities.js.map +1 -1
  41. package/dist/SharedTree.js +69 -33
  42. package/dist/SharedTree.js.map +1 -1
  43. package/dist/SharedTreeEncoder.js +4 -2
  44. package/dist/SharedTreeEncoder.js.map +1 -1
  45. package/dist/StringInterner.js +2 -2
  46. package/dist/StringInterner.js.map +1 -1
  47. package/dist/Summary.js +1 -2
  48. package/dist/Summary.js.map +1 -1
  49. package/dist/SummaryBackCompatibility.js +2 -3
  50. package/dist/SummaryBackCompatibility.js.map +1 -1
  51. package/dist/SummaryTestUtilities.js +2 -3
  52. package/dist/SummaryTestUtilities.js.map +1 -1
  53. package/dist/Transaction.js +4 -0
  54. package/dist/Transaction.js.map +1 -1
  55. package/dist/TransactionInternal.js +8 -7
  56. package/dist/TransactionInternal.js.map +1 -1
  57. package/dist/TreeCompressor.js +2 -0
  58. package/dist/TreeCompressor.js.map +1 -1
  59. package/dist/TreeNodeHandle.js +2 -0
  60. package/dist/TreeNodeHandle.js.map +1 -1
  61. package/dist/TreeView.js +9 -0
  62. package/dist/TreeView.js.map +1 -1
  63. package/dist/TreeViewUtilities.js +3 -4
  64. package/dist/TreeViewUtilities.js.map +1 -1
  65. package/dist/UndoRedoHandler.js +9 -6
  66. package/dist/UndoRedoHandler.js.map +1 -1
  67. package/dist/UuidUtilities.js +6 -6
  68. package/dist/UuidUtilities.js.map +1 -1
  69. package/dist/id-compressor/AppendOnlySortedMap.js +11 -8
  70. package/dist/id-compressor/AppendOnlySortedMap.js.map +1 -1
  71. package/dist/id-compressor/IdCompressor.js +73 -61
  72. package/dist/id-compressor/IdCompressor.js.map +1 -1
  73. package/dist/id-compressor/IdRange.js +1 -2
  74. package/dist/id-compressor/IdRange.js.map +1 -1
  75. package/dist/id-compressor/NumericUuid.js +7 -8
  76. package/dist/id-compressor/NumericUuid.js.map +1 -1
  77. package/dist/id-compressor/SessionIdNormalizer.js +9 -8
  78. package/dist/id-compressor/SessionIdNormalizer.js.map +1 -1
  79. package/dist/migration-shim/migrationDeltaHandler.js +6 -1
  80. package/dist/migration-shim/migrationDeltaHandler.js.map +1 -1
  81. package/dist/migration-shim/migrationShim.js +46 -30
  82. package/dist/migration-shim/migrationShim.js.map +1 -1
  83. package/dist/migration-shim/migrationShimFactory.js +3 -0
  84. package/dist/migration-shim/migrationShimFactory.js.map +1 -1
  85. package/dist/migration-shim/sharedTreeDeltaHandler.js +3 -1
  86. package/dist/migration-shim/sharedTreeDeltaHandler.js.map +1 -1
  87. package/dist/migration-shim/sharedTreeShim.js +7 -0
  88. package/dist/migration-shim/sharedTreeShim.js.map +1 -1
  89. package/dist/migration-shim/sharedTreeShimFactory.js +1 -0
  90. package/dist/migration-shim/sharedTreeShimFactory.js.map +1 -1
  91. package/dist/migration-shim/shimChannelServices.js +1 -0
  92. package/dist/migration-shim/shimChannelServices.js.map +1 -1
  93. package/dist/migration-shim/shimDeltaConnection.js +6 -1
  94. package/dist/migration-shim/shimDeltaConnection.js.map +1 -1
  95. package/dist/migration-shim/shimHandle.js +1 -0
  96. package/dist/migration-shim/shimHandle.js.map +1 -1
  97. package/dist/migration-shim/utils.js +3 -4
  98. package/dist/migration-shim/utils.js.map +1 -1
  99. package/dist/persisted-types/0.1.1.d.ts.map +1 -1
  100. package/lib/ChangeCompression.js +1 -0
  101. package/lib/ChangeCompression.js.map +1 -1
  102. package/lib/ChangeTypes.d.ts.map +1 -1
  103. package/lib/Checkout.js +28 -1
  104. package/lib/Checkout.js.map +1 -1
  105. package/lib/Common.js +1 -1
  106. package/lib/Common.js.map +1 -1
  107. package/lib/EditLog.d.ts.map +1 -1
  108. package/lib/EditLog.js +12 -8
  109. package/lib/EditLog.js.map +1 -1
  110. package/lib/Forest.js +9 -0
  111. package/lib/Forest.js.map +1 -1
  112. package/lib/LazyCheckout.js +1 -0
  113. package/lib/LazyCheckout.js.map +1 -1
  114. package/lib/LogViewer.js +50 -16
  115. package/lib/LogViewer.js.map +1 -1
  116. package/lib/MergeHealth.js +119 -121
  117. package/lib/MergeHealth.js.map +1 -1
  118. package/lib/RevisionValueCache.js +18 -6
  119. package/lib/RevisionValueCache.js.map +1 -1
  120. package/lib/SharedTree.js +69 -33
  121. package/lib/SharedTree.js.map +1 -1
  122. package/lib/SharedTreeEncoder.js +4 -2
  123. package/lib/SharedTreeEncoder.js.map +1 -1
  124. package/lib/StringInterner.js +2 -2
  125. package/lib/StringInterner.js.map +1 -1
  126. package/lib/Transaction.js +4 -0
  127. package/lib/Transaction.js.map +1 -1
  128. package/lib/TransactionInternal.js +8 -7
  129. package/lib/TransactionInternal.js.map +1 -1
  130. package/lib/TreeCompressor.js +2 -0
  131. package/lib/TreeCompressor.js.map +1 -1
  132. package/lib/TreeNodeHandle.js +2 -0
  133. package/lib/TreeNodeHandle.js.map +1 -1
  134. package/lib/TreeView.js +9 -0
  135. package/lib/TreeView.js.map +1 -1
  136. package/lib/UndoRedoHandler.js +9 -6
  137. package/lib/UndoRedoHandler.js.map +1 -1
  138. package/lib/id-compressor/AppendOnlySortedMap.js +11 -8
  139. package/lib/id-compressor/AppendOnlySortedMap.js.map +1 -1
  140. package/lib/id-compressor/IdCompressor.js +69 -57
  141. package/lib/id-compressor/IdCompressor.js.map +1 -1
  142. package/lib/id-compressor/SessionIdNormalizer.js +9 -8
  143. package/lib/id-compressor/SessionIdNormalizer.js.map +1 -1
  144. package/lib/migration-shim/migrationDeltaHandler.js +6 -1
  145. package/lib/migration-shim/migrationDeltaHandler.js.map +1 -1
  146. package/lib/migration-shim/migrationShim.js +46 -30
  147. package/lib/migration-shim/migrationShim.js.map +1 -1
  148. package/lib/migration-shim/migrationShimFactory.js +3 -0
  149. package/lib/migration-shim/migrationShimFactory.js.map +1 -1
  150. package/lib/migration-shim/sharedTreeDeltaHandler.js +3 -1
  151. package/lib/migration-shim/sharedTreeDeltaHandler.js.map +1 -1
  152. package/lib/migration-shim/sharedTreeShim.js +7 -0
  153. package/lib/migration-shim/sharedTreeShim.js.map +1 -1
  154. package/lib/migration-shim/sharedTreeShimFactory.js +1 -0
  155. package/lib/migration-shim/sharedTreeShimFactory.js.map +1 -1
  156. package/lib/migration-shim/shimChannelServices.js +1 -0
  157. package/lib/migration-shim/shimChannelServices.js.map +1 -1
  158. package/lib/migration-shim/shimDeltaConnection.js +6 -1
  159. package/lib/migration-shim/shimDeltaConnection.js.map +1 -1
  160. package/lib/migration-shim/shimHandle.js +1 -0
  161. package/lib/migration-shim/shimHandle.js.map +1 -1
  162. package/lib/persisted-types/0.1.1.d.ts.map +1 -1
  163. package/package.json +37 -41
  164. package/tsconfig.json +3 -4
@@ -4,7 +4,12 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.isStableId = exports.assertIsStableId = exports.generateStableId = exports.isUuidString = exports.assertIsUuidString = exports.nilUuid = void 0;
7
+ exports.nilUuid = void 0;
8
+ exports.assertIsUuidString = assertIsUuidString;
9
+ exports.isUuidString = isUuidString;
10
+ exports.generateStableId = generateStableId;
11
+ exports.assertIsStableId = assertIsStableId;
12
+ exports.isStableId = isStableId;
8
13
  const uuid_1 = require("uuid");
9
14
  const Common_js_1 = require("./Common.js");
10
15
  const hexadecimalCharCodes = Array.from('09afAF').map((c) => c.charCodeAt(0));
@@ -22,7 +27,6 @@ function assertIsUuidString(uuidString) {
22
27
  (0, Common_js_1.assertWithMessage)(isUuidString(uuidString), `${uuidString} is not an UuidString`);
23
28
  return uuidString;
24
29
  }
25
- exports.assertIsUuidString = assertIsUuidString;
26
30
  /**
27
31
  * Returns true iff the given string is a valid UUID-like string of hexadecimal characters
28
32
  * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
@@ -47,14 +51,12 @@ function isUuidString(str) {
47
51
  }
48
52
  return true;
49
53
  }
50
- exports.isUuidString = isUuidString;
51
54
  /**
52
55
  * Generate a random stable ID
53
56
  */
54
57
  function generateStableId() {
55
58
  return assertIsStableId((0, uuid_1.v4)());
56
59
  }
57
- exports.generateStableId = generateStableId;
58
60
  /**
59
61
  * Asserts that the given string is a stable ID.
60
62
  */
@@ -62,7 +64,6 @@ function assertIsStableId(stableId) {
62
64
  (0, Common_js_1.assertWithMessage)(isStableId(stableId), `${stableId} is not a StableId.`);
63
65
  return stableId;
64
66
  }
65
- exports.assertIsStableId = assertIsStableId;
66
67
  /**
67
68
  * Returns true iff the given string is a valid Version 4, variant 2 UUID
68
69
  * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
@@ -102,5 +103,4 @@ function isStableId(str) {
102
103
  }
103
104
  return true;
104
105
  }
105
- exports.isStableId = isStableId;
106
106
  //# sourceMappingURL=UuidUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UuidUtilities.js","sourceRoot":"","sources":["../src/UuidUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,2CAAgD;AAGhD,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAO3E,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC/C,OAAO,CACN,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC;AAED,uCAAuC;AAC1B,QAAA,OAAO,GAAG,kBAAkB,CAAC,UAAG,CAAC,CAAC;AAE/C;;GAEG;AACH,SAAgB,kBAAkB,CAAC,UAAkB;IACpD,IAAA,6BAAiB,EAAC,YAAY,CAAC,UAAU,CAAC,E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Q,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,CAAC;YACP,KAAK,EAAE,CAAC;YACR,KAAK,EAAE,CAAC;YACR,KAAK,EAAE;gBACN,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YAEP,KAAK,EAAE;gBACN,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YAEP,KAAK,EAAE,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;oBAClE,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YACP,CAAC;YAED;gBACC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChD,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;QACR,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAvCD,gCAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NIL, v4 } from 'uuid';\n\nimport { assertWithMessage } from './Common.js';\nimport { StableId, UuidString } from './Identifiers.js';\n\nconst hexadecimalCharCodes = Array.from('09afAF').map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/** The null (lowest/all-zeros) UUID */\nexport const nilUuid = assertIsUuidString(NIL);\n\n/**\n * Asserts that the given string is a UUID\n */\nexport function assertIsUuidString(uuidString: string): UuidString {\n\tassertWithMessage(isUuidString(uuidString), `${uuidString} is not an UuidString`);\n\treturn uuidString;\n}\n\n/**\n * Returns true iff the given string is a valid UUID-like string of hexadecimal characters\n * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\n */\nexport function isUuidString(str: string): str is UuidString {\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Generate a random stable ID\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassertWithMessage(isStableId(stableId), `${stableId} is not a StableId.`);\n\treturn stableId;\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== '4') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== '8' && char !== '9' && char !== 'a' && char !== 'b') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"UuidUtilities.js","sourceRoot":"","sources":["../src/UuidUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA8BH,gDAGC;AAMD,oCAqBC;AAKD,4CAEC;AAKD,4CAGC;AAMD,gCAuCC;AAtHD,+BAA+B;AAE/B,2CAAgD;AAGhD,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAO3E,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC/C,OAAO,CACN,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC;AAED,uCAAuC;AAC1B,QAA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AAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,QAAQ,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,CAAC;YACP,KAAK,EAAE,CAAC;YACR,KAAK,EAAE,CAAC;YACR,KAAK,EAAE;gBACN,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YAEP,KAAK,EAAE;gBACN,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YAEP,KAAK,EAAE,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;oBAClE,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YACP,CAAC;YAED;gBACC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChD,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;QACR,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NIL, v4 } from 'uuid';\n\nimport { assertWithMessage } from './Common.js';\nimport { StableId, UuidString } from './Identifiers.js';\n\nconst hexadecimalCharCodes = Array.from('09afAF').map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/** The null (lowest/all-zeros) UUID */\nexport const nilUuid = assertIsUuidString(NIL);\n\n/**\n * Asserts that the given string is a UUID\n */\nexport function assertIsUuidString(uuidString: string): UuidString {\n\tassertWithMessage(isUuidString(uuidString), `${uuidString} is not an UuidString`);\n\treturn uuidString;\n}\n\n/**\n * Returns true iff the given string is a valid UUID-like string of hexadecimal characters\n * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\n */\nexport function isUuidString(str: string): str is UuidString {\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Generate a random stable ID\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassertWithMessage(isStableId(stableId), `${stableId} is not a StableId.`);\n\treturn stableId;\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== '4') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== '8' && char !== '9' && char !== 'a' && char !== 'b') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
@@ -13,12 +13,13 @@ const Common_js_1 = require("../Common.js");
13
13
  * Supports appending and searching.
14
14
  */
15
15
  class AppendOnlySortedMap {
16
+ comparator;
17
+ elements = [];
16
18
  /**
17
19
  * @param comparator - a comparator for keys
18
20
  */
19
21
  constructor(comparator) {
20
22
  this.comparator = comparator;
21
- this.elements = [];
22
23
  }
23
24
  /**
24
25
  * Gets the number of entries in this map
@@ -261,6 +262,10 @@ class AppendOnlySortedMap {
261
262
  }
262
263
  return keyIndex;
263
264
  }
265
+ /**
266
+ * The value xor'd with the result index when a search fails.
267
+ */
268
+ static failureXor = -1;
264
269
  /**
265
270
  * Performs a binary search on the sorted array.
266
271
  * @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd
@@ -292,22 +297,17 @@ class AppendOnlySortedMap {
292
297
  }
293
298
  }
294
299
  exports.AppendOnlySortedMap = AppendOnlySortedMap;
295
- /**
296
- * The value xor'd with the result index when a search fails.
297
- */
298
- AppendOnlySortedMap.failureXor = -1;
299
300
  /**
300
301
  * A map in which entries are always added in both key-sorted and value-sorted order.
301
302
  * Supports appending and searching.
302
303
  */
303
304
  class AppendOnlyDoublySortedMap extends AppendOnlySortedMap {
305
+ extractSearchValue;
306
+ valueComparator;
304
307
  constructor(keyComparator, extractSearchValue, valueComparator) {
305
308
  super(keyComparator);
306
309
  this.extractSearchValue = extractSearchValue;
307
310
  this.valueComparator = valueComparator;
308
- this.compareValues = (search, _, value) => {
309
- return this.valueComparator(search, this.extractSearchValue(value));
310
- };
311
311
  }
312
312
  append(key, value) {
313
313
  if (this.elements.length !== 0 &&
@@ -316,6 +316,9 @@ class AppendOnlyDoublySortedMap extends AppendOnlySortedMap {
316
316
  }
317
317
  super.append(key, value);
318
318
  }
319
+ compareValues = (search, _, value) => {
320
+ return this.valueComparator(search, this.extractSearchValue(value));
321
+ };
319
322
  /**
320
323
  * @param value - the value to lookup.
321
324
  * @returns the key associated with `value` if such an entry exists, and undefined otherwise.
@@ -1 +1 @@
1
- {"version":3,"file":"AppendOnlySortedMap.js","sourceRoot":"","sources":["../../src/id-compressor/AppendOnlySortedMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,kEAA6D;AAE7D,4CAAoC;AAEpC;;;GAGG;AACH,MAAa,mBAAmB;IAG/B;;OAEG;IACH,YAAsC,UAAkC;QAAlC,eAAU,GAAV,UAAU,CAAwB;QALrD,aAAQ,GAAc,EAAE,CAAC;IAK+B,CAAC;IAE5E;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAkB,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAkB,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,C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AAI,GAAG,EAAE,CAAC;QACX,CAAC;IACF,CAAC;CACD;AApED,8DAoEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { fail } from '../Common.js';\n\n/**\n * A map in which entries are always added in key-sorted order.\n * Supports appending and searching.\n */\nexport class AppendOnlySortedMap<K, V> {\n\tprotected readonly elements: (K | V)[] = [];\n\n\t/**\n\t * @param comparator - a comparator for keys\n\t */\n\tpublic constructor(protected readonly comparator: (a: K, b: K) => number) {}\n\n\t/**\n\t * Gets the number of entries in this map\n\t */\n\tpublic get size(): number {\n\t\treturn this.elements.length / 2;\n\t}\n\n\t/**\n\t * Gets the min key in the map.\n\t */\n\tpublic minKey(): K | undefined {\n\t\treturn this.elements[0] as K | undefined;\n\t}\n\n\t/**\n\t * Gets the max key in the map.\n\t */\n\tpublic maxKey(): K | undefined {\n\t\treturn this.elements[this.elements.length - 2] as K | undefined;\n\t}\n\n\t/**\n\t * Gets the min value in the map.\n\t */\n\tpublic minValue(): V | undefined {\n\t\treturn this.elements[1] as V | undefined;\n\t}\n\n\t/**\n\t * Gets the max value in the map.\n\t */\n\tpublic maxValue(): V | undefined {\n\t\treturn this.elements[this.elements.length - 1] as V | undefined;\n\t}\n\n\t/**\n\t * Gets the first entry in the map.\n\t */\n\tpublic first(): [K, V] | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [elements[0] as K, elements[1] as V];\n\t}\n\n\t/**\n\t * Gets the last entry in the map.\n\t */\n\tpublic last(): [K, V] | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst lastKeyIndex = length - 2;\n\t\treturn [elements[lastKeyIndex] as K, elements[lastKeyIndex + 1] as V];\n\t}\n\n\t/**\n\t * Returns the element at the insertion index.\n\t */\n\tpublic getAtIndex(index: number): [K, V] | undefined {\n\t\tconst realIndex = index * 2;\n\t\tconst { elements } = this;\n\t\tif (realIndex < 0 || realIndex > elements.length - 1) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [elements[realIndex] as K, elements[realIndex + 1] as V];\n\t}\n\n\t/**\n\t * Gets an iterable of the entries in the map.\n\t */\n\tpublic *entries(): IterableIterator<readonly [K, V]> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield [elements[i] as K, elements[i + 1] as V];\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the keys in the map.\n\t */\n\tpublic *keys(): IterableIterator<K> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield elements[i] as K;\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the values in the map.\n\t */\n\tpublic *values(): IterableIterator<V> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield elements[i + 1] as V;\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the entries in the map, reversed.\n\t */\n\tpublic *entriesReversed(): IterableIterator<readonly [K, V]> {\n\t\tconst { elements } = this;\n\t\tfor (let i = elements.length - 2; i >= 0; i -= 2) {\n\t\t\tyield [elements[i] as K, elements[i + 1] as V];\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new key/value pair to the map. `key` must be \\> to all keys in the map.\n\t * @param key - The key to add.\n\t * @param value - The value to add.\n\t */\n\tpublic append(key: K, value: V): void {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length !== 0 && this.comparator(key, this.maxKey() as K) <= 0) {\n\t\t\tfail('Inserted key must be > all others in the map.');\n\t\t}\n\t\telements.push(key);\n\t\telements.push(value);\n\t}\n\n\t/**\n\t * Gets the value associated with `key` if such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic get(key: K): V | undefined {\n\t\tconst index = AppendOnlySortedMap.keyIndexOf(this.elements, key, this.comparator);\n\t\tif (index < 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.elements[index + 1] as V;\n\t}\n\n\t/**\n\t * Gets the entry associated with `key` if such an entry exists, the entry associated with the next lower key if\n\t * such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic getPairOrNextLower(key: K): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextLowerBy(key, this.comparator);\n\t}\n\n\t/**\n\t * Gets the entry associated with `key` if such an entry exists, the entry associated with the next higher key if\n\t * such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic getPairOrNextHigher(key: K): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextHigherBy(key, this.comparator);\n\t}\n\n\t/**\n\t * Compares two `AppendOnlySortedMap`s.\n\t */\n\tpublic equals(other: AppendOnlySortedMap<K, V>, compareValues: (a: V, b: V) => boolean): boolean {\n\t\tif (other === this) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.elements.length !== other.elements.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = this.elements.length - 2; i >= 0; i -= 2) {\n\t\t\tconst keyThis = this.elements[i] as K;\n\t\t\tconst valueThis = this.elements[i + 1] as V;\n\t\t\tconst keyOther = other.elements[i] as K;\n\t\t\tconst valueOther = other.elements[i + 1] as V;\n\t\t\tif (this.comparator(keyThis, keyOther) !== 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (!compareValues(valueThis, valueOther)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Test-only expensive assertions to check the internal validity of the data structure.\n\t */\n\tpublic assertValid(): void {\n\t\tlet prev: readonly [K, unknown] | undefined;\n\t\tfor (const kv of this.entries()) {\n\t\t\tif (prev !== undefined) {\n\t\t\t\tassert(this.comparator(kv[0], prev[0]) > 0, 0x63e /* Keys in map must be sorted. */);\n\t\t\t}\n\t\t\tprev = kv;\n\t\t}\n\t}\n\n\t/**\n\t * Queries a range of entries.\n\t * @param from - the key to start the range query at, inclusive.\n\t * @param to - the key to end the range query at, inclusive.\n\t * @returns the range of entries.\n\t */\n\tpublic *getRange(from: K, to: K): IterableIterator<readonly [K, V]> {\n\t\tconst keyIndexFrom = this.getKeyIndexOfOrNextHigher(from, this.comparator);\n\t\tif (keyIndexFrom === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst keyIndexTo = this.getKeyIndexOfOrNextLower(to, this.comparator);\n\t\tif (keyIndexTo === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (let i = keyIndexFrom; i <= keyIndexTo; i += 2) {\n\t\t\tyield [this.elements[i] as K, this.elements[i + 1] as V];\n\t\t}\n\t}\n\n\tprotected getPairOrNextLowerBy<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): readonly [K, V] | undefined {\n\t\tconst keyIndex = this.getKeyIndexOfOrNextLower(search, comparator);\n\t\tif (keyIndex === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];\n\t}\n\n\tprivate getKeyIndexOfOrNextLower<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number | undefined {\n\t\tconst { elements } = this;\n\t\tif (elements.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);\n\t\tif (keyIndex < 0) {\n\t\t\tkeyIndex ^= AppendOnlySortedMap.failureXor;\n\t\t\tif (keyIndex > 0) {\n\t\t\t\treturn keyIndex - 2;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn keyIndex;\n\t}\n\n\tprotected getPairOrNextHigherBy<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): readonly [K, V] | undefined {\n\t\tconst keyIndex = this.getKeyIndexOfOrNextHigher(search, comparator);\n\t\tif (keyIndex === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];\n\t}\n\n\tprivate getKeyIndexOfOrNextHigher<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);\n\t\tif (keyIndex < 0) {\n\t\t\tkeyIndex ^= AppendOnlySortedMap.failureXor;\n\t\t\tif (keyIndex < length) {\n\t\t\t\treturn keyIndex;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn keyIndex;\n\t}\n\n\t/**\n\t * The value xor'd with the result index when a search fails.\n\t */\n\tpublic static readonly failureXor = -1;\n\n\t/**\n\t * Performs a binary search on the sorted array.\n\t * @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd\n\t * with `failureXor`. Note that negating is not an adequate solution as that could result in -0.\n\t */\n\tpublic static keyIndexOf<T, K, V>(\n\t\telements: readonly (K | V)[],\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number {\n\t\t// Low, high, and mid are addresses of [K,V] pairs and *not* key indices\n\t\tlet low = 0;\n\t\tlet high = elements.length / 2;\n\t\tlet mid = high >> 1;\n\t\twhile (low < high) {\n\t\t\tconst keyIndex = mid * 2;\n\t\t\tconst c = comparator(search, elements[keyIndex] as K, elements[keyIndex + 1] as V);\n\t\t\tif (c > 0) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else if (c < 0) {\n\t\t\t\thigh = mid;\n\t\t\t} else if (c === 0) {\n\t\t\t\treturn keyIndex;\n\t\t\t} else {\n\t\t\t\tfail('Invalid comparator.');\n\t\t\t}\n\t\t\tmid = (low + high) >> 1;\n\t\t}\n\t\treturn (mid * 2) ^ AppendOnlySortedMap.failureXor;\n\t}\n}\n\n/**\n * A map in which entries are always added in both key-sorted and value-sorted order.\n * Supports appending and searching.\n */\nexport class AppendOnlyDoublySortedMap<K, V, S> extends AppendOnlySortedMap<K, V> {\n\tpublic constructor(\n\t\tkeyComparator: (a: K, b: K) => number,\n\t\tprivate readonly extractSearchValue: (value: V) => S,\n\t\tprivate readonly valueComparator: (search: S, value: S) => number\n\t) {\n\t\tsuper(keyComparator);\n\t}\n\n\tpublic append(key: K, value: V): void {\n\t\tif (\n\t\t\tthis.elements.length !== 0 &&\n\t\t\tthis.valueComparator(this.extractSearchValue(value), this.extractSearchValue(this.maxValue() as V)) <= 0\n\t\t) {\n\t\t\tfail('Inserted value must be > all others in the map.');\n\t\t}\n\t\tsuper.append(key, value);\n\t}\n\n\tprivate readonly compareValues = (search: S, _: K, value: V): number => {\n\t\treturn this.valueComparator(search, this.extractSearchValue(value));\n\t};\n\n\t/**\n\t * @param value - the value to lookup.\n\t * @returns the key associated with `value` if such an entry exists, and undefined otherwise.\n\t */\n\tpublic getByValue(value: S): K | undefined {\n\t\tconst index = AppendOnlySortedMap.keyIndexOf(this.elements, value, this.compareValues);\n\t\treturn this.elements[index]?.[0];\n\t}\n\n\t/**\n\t * @param searchValue - the search value to lookup.\n\t * @returns the entry who's value, when run through the extractor provided to the constructor, matches\n\t * `searchValue`. If no such entry exists, this method returns the next lower entry as determined by the value\n\t * comparator provided to the constructor. If no such entry exists, this method returns undefined.\n\t */\n\tpublic getPairOrNextLowerByValue(searchValue: S): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextLowerBy(searchValue, this.compareValues);\n\t}\n\n\t/**\n\t * @param searchValue - the search value to lookup.\n\t * @returns the entry who's value, when run through the extractor provided to the constructor, matches `searchValue`. If no such entry\n\t * exists, this method returns the next higher entry as determined by the value comparator provided to the constructor. If no such entry\n\t * exists, this method returns undefined.\n\t */\n\tpublic getPairOrNextHigherByValue(searchValue: S): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextHigherBy(searchValue, this.compareValues);\n\t}\n\n\t/**\n\t * Test-only expensive assertions to check the internal validity of the data structure.\n\t */\n\tpublic assertValid(): void {\n\t\tsuper.assertValid();\n\t\tlet prev: readonly [unknown, V] | undefined;\n\t\tfor (const kv of this.entries()) {\n\t\t\tif (prev !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.valueComparator(this.extractSearchValue(kv[1]), this.extractSearchValue(prev[1])) > 0,\n\t\t\t\t\t0x63f /* Values in map must be sorted. */\n\t\t\t\t);\n\t\t\t}\n\t\t\tprev = kv;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"AppendOnlySortedMap.js","sourceRoot":"","sources":["../../src/id-compressor/AppendOnlySortedMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,kEAA6D;AAE7D,4CAAoC;AAEpC;;;GAGG;AACH,MAAa,mBAAmB;IAMO;IALnB,QAAQ,GAAc,EAAE,CAAC;IAE5C;;OAEG;IACH,YAAsC,UAAkC;QAAlC,eAAU,GAAV,UAAU,CAAwB;IAAG,CAAC;IAE5E;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAkB,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAkB,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAkB,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,OAAO,IAAI,CAA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AoEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { fail } from '../Common.js';\n\n/**\n * A map in which entries are always added in key-sorted order.\n * Supports appending and searching.\n */\nexport class AppendOnlySortedMap<K, V> {\n\tprotected readonly elements: (K | V)[] = [];\n\n\t/**\n\t * @param comparator - a comparator for keys\n\t */\n\tpublic constructor(protected readonly comparator: (a: K, b: K) => number) {}\n\n\t/**\n\t * Gets the number of entries in this map\n\t */\n\tpublic get size(): number {\n\t\treturn this.elements.length / 2;\n\t}\n\n\t/**\n\t * Gets the min key in the map.\n\t */\n\tpublic minKey(): K | undefined {\n\t\treturn this.elements[0] as K | undefined;\n\t}\n\n\t/**\n\t * Gets the max key in the map.\n\t */\n\tpublic maxKey(): K | undefined {\n\t\treturn this.elements[this.elements.length - 2] as K | undefined;\n\t}\n\n\t/**\n\t * Gets the min value in the map.\n\t */\n\tpublic minValue(): V | undefined {\n\t\treturn this.elements[1] as V | undefined;\n\t}\n\n\t/**\n\t * Gets the max value in the map.\n\t */\n\tpublic maxValue(): V | undefined {\n\t\treturn this.elements[this.elements.length - 1] as V | undefined;\n\t}\n\n\t/**\n\t * Gets the first entry in the map.\n\t */\n\tpublic first(): [K, V] | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [elements[0] as K, elements[1] as V];\n\t}\n\n\t/**\n\t * Gets the last entry in the map.\n\t */\n\tpublic last(): [K, V] | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst lastKeyIndex = length - 2;\n\t\treturn [elements[lastKeyIndex] as K, elements[lastKeyIndex + 1] as V];\n\t}\n\n\t/**\n\t * Returns the element at the insertion index.\n\t */\n\tpublic getAtIndex(index: number): [K, V] | undefined {\n\t\tconst realIndex = index * 2;\n\t\tconst { elements } = this;\n\t\tif (realIndex < 0 || realIndex > elements.length - 1) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [elements[realIndex] as K, elements[realIndex + 1] as V];\n\t}\n\n\t/**\n\t * Gets an iterable of the entries in the map.\n\t */\n\tpublic *entries(): IterableIterator<readonly [K, V]> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield [elements[i] as K, elements[i + 1] as V];\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the keys in the map.\n\t */\n\tpublic *keys(): IterableIterator<K> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield elements[i] as K;\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the values in the map.\n\t */\n\tpublic *values(): IterableIterator<V> {\n\t\tconst { elements } = this;\n\t\tfor (let i = 0; i < elements.length; i += 2) {\n\t\t\tyield elements[i + 1] as V;\n\t\t}\n\t}\n\n\t/**\n\t * Gets an iterable of the entries in the map, reversed.\n\t */\n\tpublic *entriesReversed(): IterableIterator<readonly [K, V]> {\n\t\tconst { elements } = this;\n\t\tfor (let i = elements.length - 2; i >= 0; i -= 2) {\n\t\t\tyield [elements[i] as K, elements[i + 1] as V];\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new key/value pair to the map. `key` must be \\> to all keys in the map.\n\t * @param key - The key to add.\n\t * @param value - The value to add.\n\t */\n\tpublic append(key: K, value: V): void {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length !== 0 && this.comparator(key, this.maxKey() as K) <= 0) {\n\t\t\tfail('Inserted key must be > all others in the map.');\n\t\t}\n\t\telements.push(key);\n\t\telements.push(value);\n\t}\n\n\t/**\n\t * Gets the value associated with `key` if such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic get(key: K): V | undefined {\n\t\tconst index = AppendOnlySortedMap.keyIndexOf(this.elements, key, this.comparator);\n\t\tif (index < 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.elements[index + 1] as V;\n\t}\n\n\t/**\n\t * Gets the entry associated with `key` if such an entry exists, the entry associated with the next lower key if\n\t * such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic getPairOrNextLower(key: K): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextLowerBy(key, this.comparator);\n\t}\n\n\t/**\n\t * Gets the entry associated with `key` if such an entry exists, the entry associated with the next higher key if\n\t * such an entry exists, and `undefined` otherwise.\n\t * @param key - The key to lookup.\n\t */\n\tpublic getPairOrNextHigher(key: K): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextHigherBy(key, this.comparator);\n\t}\n\n\t/**\n\t * Compares two `AppendOnlySortedMap`s.\n\t */\n\tpublic equals(other: AppendOnlySortedMap<K, V>, compareValues: (a: V, b: V) => boolean): boolean {\n\t\tif (other === this) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.elements.length !== other.elements.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = this.elements.length - 2; i >= 0; i -= 2) {\n\t\t\tconst keyThis = this.elements[i] as K;\n\t\t\tconst valueThis = this.elements[i + 1] as V;\n\t\t\tconst keyOther = other.elements[i] as K;\n\t\t\tconst valueOther = other.elements[i + 1] as V;\n\t\t\tif (this.comparator(keyThis, keyOther) !== 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (!compareValues(valueThis, valueOther)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Test-only expensive assertions to check the internal validity of the data structure.\n\t */\n\tpublic assertValid(): void {\n\t\tlet prev: readonly [K, unknown] | undefined;\n\t\tfor (const kv of this.entries()) {\n\t\t\tif (prev !== undefined) {\n\t\t\t\tassert(this.comparator(kv[0], prev[0]) > 0, 0x63e /* Keys in map must be sorted. */);\n\t\t\t}\n\t\t\tprev = kv;\n\t\t}\n\t}\n\n\t/**\n\t * Queries a range of entries.\n\t * @param from - the key to start the range query at, inclusive.\n\t * @param to - the key to end the range query at, inclusive.\n\t * @returns the range of entries.\n\t */\n\tpublic *getRange(from: K, to: K): IterableIterator<readonly [K, V]> {\n\t\tconst keyIndexFrom = this.getKeyIndexOfOrNextHigher(from, this.comparator);\n\t\tif (keyIndexFrom === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst keyIndexTo = this.getKeyIndexOfOrNextLower(to, this.comparator);\n\t\tif (keyIndexTo === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (let i = keyIndexFrom; i <= keyIndexTo; i += 2) {\n\t\t\tyield [this.elements[i] as K, this.elements[i + 1] as V];\n\t\t}\n\t}\n\n\tprotected getPairOrNextLowerBy<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): readonly [K, V] | undefined {\n\t\tconst keyIndex = this.getKeyIndexOfOrNextLower(search, comparator);\n\t\tif (keyIndex === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];\n\t}\n\n\tprivate getKeyIndexOfOrNextLower<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number | undefined {\n\t\tconst { elements } = this;\n\t\tif (elements.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);\n\t\tif (keyIndex < 0) {\n\t\t\tkeyIndex ^= AppendOnlySortedMap.failureXor;\n\t\t\tif (keyIndex > 0) {\n\t\t\t\treturn keyIndex - 2;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn keyIndex;\n\t}\n\n\tprotected getPairOrNextHigherBy<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): readonly [K, V] | undefined {\n\t\tconst keyIndex = this.getKeyIndexOfOrNextHigher(search, comparator);\n\t\tif (keyIndex === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];\n\t}\n\n\tprivate getKeyIndexOfOrNextHigher<T>(\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number | undefined {\n\t\tconst { elements } = this;\n\t\tconst { length } = elements;\n\t\tif (length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);\n\t\tif (keyIndex < 0) {\n\t\t\tkeyIndex ^= AppendOnlySortedMap.failureXor;\n\t\t\tif (keyIndex < length) {\n\t\t\t\treturn keyIndex;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn keyIndex;\n\t}\n\n\t/**\n\t * The value xor'd with the result index when a search fails.\n\t */\n\tpublic static readonly failureXor = -1;\n\n\t/**\n\t * Performs a binary search on the sorted array.\n\t * @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd\n\t * with `failureXor`. Note that negating is not an adequate solution as that could result in -0.\n\t */\n\tpublic static keyIndexOf<T, K, V>(\n\t\telements: readonly (K | V)[],\n\t\tsearch: T,\n\t\tcomparator: (search: T, key: K, value: V) => number\n\t): number {\n\t\t// Low, high, and mid are addresses of [K,V] pairs and *not* key indices\n\t\tlet low = 0;\n\t\tlet high = elements.length / 2;\n\t\tlet mid = high >> 1;\n\t\twhile (low < high) {\n\t\t\tconst keyIndex = mid * 2;\n\t\t\tconst c = comparator(search, elements[keyIndex] as K, elements[keyIndex + 1] as V);\n\t\t\tif (c > 0) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else if (c < 0) {\n\t\t\t\thigh = mid;\n\t\t\t} else if (c === 0) {\n\t\t\t\treturn keyIndex;\n\t\t\t} else {\n\t\t\t\tfail('Invalid comparator.');\n\t\t\t}\n\t\t\tmid = (low + high) >> 1;\n\t\t}\n\t\treturn (mid * 2) ^ AppendOnlySortedMap.failureXor;\n\t}\n}\n\n/**\n * A map in which entries are always added in both key-sorted and value-sorted order.\n * Supports appending and searching.\n */\nexport class AppendOnlyDoublySortedMap<K, V, S> extends AppendOnlySortedMap<K, V> {\n\tpublic constructor(\n\t\tkeyComparator: (a: K, b: K) => number,\n\t\tprivate readonly extractSearchValue: (value: V) => S,\n\t\tprivate readonly valueComparator: (search: S, value: S) => number\n\t) {\n\t\tsuper(keyComparator);\n\t}\n\n\tpublic append(key: K, value: V): void {\n\t\tif (\n\t\t\tthis.elements.length !== 0 &&\n\t\t\tthis.valueComparator(this.extractSearchValue(value), this.extractSearchValue(this.maxValue() as V)) <= 0\n\t\t) {\n\t\t\tfail('Inserted value must be > all others in the map.');\n\t\t}\n\t\tsuper.append(key, value);\n\t}\n\n\tprivate readonly compareValues = (search: S, _: K, value: V): number => {\n\t\treturn this.valueComparator(search, this.extractSearchValue(value));\n\t};\n\n\t/**\n\t * @param value - the value to lookup.\n\t * @returns the key associated with `value` if such an entry exists, and undefined otherwise.\n\t */\n\tpublic getByValue(value: S): K | undefined {\n\t\tconst index = AppendOnlySortedMap.keyIndexOf(this.elements, value, this.compareValues);\n\t\treturn this.elements[index]?.[0];\n\t}\n\n\t/**\n\t * @param searchValue - the search value to lookup.\n\t * @returns the entry who's value, when run through the extractor provided to the constructor, matches\n\t * `searchValue`. If no such entry exists, this method returns the next lower entry as determined by the value\n\t * comparator provided to the constructor. If no such entry exists, this method returns undefined.\n\t */\n\tpublic getPairOrNextLowerByValue(searchValue: S): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextLowerBy(searchValue, this.compareValues);\n\t}\n\n\t/**\n\t * @param searchValue - the search value to lookup.\n\t * @returns the entry who's value, when run through the extractor provided to the constructor, matches `searchValue`. If no such entry\n\t * exists, this method returns the next higher entry as determined by the value comparator provided to the constructor. If no such entry\n\t * exists, this method returns undefined.\n\t */\n\tpublic getPairOrNextHigherByValue(searchValue: S): readonly [K, V] | undefined {\n\t\treturn this.getPairOrNextHigherBy(searchValue, this.compareValues);\n\t}\n\n\t/**\n\t * Test-only expensive assertions to check the internal validity of the data structure.\n\t */\n\tpublic assertValid(): void {\n\t\tsuper.assertValid();\n\t\tlet prev: readonly [unknown, V] | undefined;\n\t\tfor (const kv of this.entries()) {\n\t\t\tif (prev !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.valueComparator(this.extractSearchValue(kv[1]), this.extractSearchValue(prev[1])) > 0,\n\t\t\t\t\t0x63f /* Values in map must be sorted. */\n\t\t\t\t);\n\t\t\t}\n\t\t\tprev = kv;\n\t\t}\n\t}\n}\n"]}
@@ -4,7 +4,10 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.hasOngoingSession = exports.IdCompressor = exports.isLocalId = exports.isFinalId = exports.legacySharedTreeInitialTreeId = exports.defaultClusterCapacity = void 0;
7
+ exports.IdCompressor = exports.legacySharedTreeInitialTreeId = exports.defaultClusterCapacity = void 0;
8
+ exports.isFinalId = isFinalId;
9
+ exports.isLocalId = isLocalId;
10
+ exports.hasOngoingSession = hasOngoingSession;
8
11
  const internal_1 = require("@fluidframework/core-utils/internal");
9
12
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
10
13
  const sorted_btree_es6_1 = require("@tylerbu/sorted-btree-es6");
@@ -37,14 +40,12 @@ exports.legacySharedTreeInitialTreeId = `24e26f0b-3c1a-47f8-a7a1-e8461ddb69ce6`;
37
40
  function isFinalId(id) {
38
41
  return id >= 0;
39
42
  }
40
- exports.isFinalId = isFinalId;
41
43
  /**
42
44
  * @returns true if the supplied ID is a local ID.
43
45
  */
44
46
  function isLocalId(id) {
45
47
  return id < 0;
46
48
  }
47
- exports.isLocalId = isLocalId;
48
49
  /** Prepended to all keys in {@link IdCompressor.clustersAndOverridesInversion} that are override strings and not valid `StableIds` */
49
50
  const nonStableOverridePrefix = '\ue15e'; // A character in the Private Use Area of the BMP (https://en.wikipedia.org/wiki/Private_Use_Areas)
50
51
  /**
@@ -113,6 +114,17 @@ const nonStableOverridePrefix = '\ue15e'; // A character in the Private Use Area
113
114
  *
114
115
  */
115
116
  class IdCompressor {
117
+ localSessionId;
118
+ reservedIdCount;
119
+ /**
120
+ * Max allowed cluster size
121
+ */
122
+ static maxClusterSize = 2 ** 20;
123
+ /**
124
+ * Trivially reach consensus on default cluster size and reserved IDs.
125
+ * These initial values must *NOT* change without careful consideration to compatibility.
126
+ */
127
+ newClusterCapacity = exports.defaultClusterCapacity;
116
128
  /**
117
129
  * The size of each newly created ID cluster.
118
130
  */
@@ -134,6 +146,64 @@ class IdCompressor {
134
146
  get attributionId() {
135
147
  return this.localSession.attributionId;
136
148
  }
149
+ /**
150
+ * Session ID -\> data about the session's current cluster.
151
+ * Sessions are mutable, and thus should only be created via `createSession`.
152
+ */
153
+ sessions = new Map();
154
+ /**
155
+ * The `IdCompressor`'s current local session.
156
+ */
157
+ localSession;
158
+ /**
159
+ * The base final ID of the next cluster to be created.
160
+ */
161
+ nextClusterBaseFinalId = 0;
162
+ /**
163
+ * Total number of IDs created locally during the current session.
164
+ */
165
+ localIdCount = 0;
166
+ /**
167
+ * The most recent (i.e. smallest, due to being negative) local ID in a range returned by `takeNextCreationRange`.
168
+ * Undefined if no non-empty ranges have ever been returned by this compressor.
169
+ */
170
+ lastTakenLocalId;
171
+ /**
172
+ * Maps local IDs to override strings. This will contain an entry for every override assigned to a local ID generated during
173
+ * the current session, and retains entries for the lifetime of this compressor.
174
+ */
175
+ localOverrides = new AppendOnlySortedMap_js_1.AppendOnlySortedMap(Common_js_1.compareFiniteNumbersReversed);
176
+ /**
177
+ * Maps local IDs to the final ID they are associated with (if any), and maps final IDs to the corresponding local ID (if any).
178
+ * This is used to efficiently compute normalization. This map can be thought of as mapping ranges of "optimistic uncertainty"
179
+ * (local IDs) to the result of consensus (reserved ranges of final IDs, a.k.a. clusters). Any given range of local IDs
180
+ * does not necessarily span an entire cluster, as some session-space IDs may be allocated *after* a cluster has been allocated
181
+ * but before it is full. In this case, there is no uncertainty, as the range of final IDs was reserved when the cluster was created.
182
+ * However, there is always a range of local IDs with size \>= 1 associated with the beginning of every cluster, as clusters are only
183
+ * created *after* they are needed and thus there is some period of uncertainty after local IDs have been handed out but before the
184
+ * range containing them has been finalized. There may also be ranges of local IDs that do not start at the beginning of a
185
+ * cluster; this happens when a cluster is expanded instead of allocating a new one.
186
+ * Additionally, session space IDs associated with an override string will also always be local IDs, because there is uncertainty as
187
+ * to whether another client simultaneously allocated the same override and could get sequenced first (a.k.a. unification) and its
188
+ * final ID would be associated with that override.
189
+ * See `SessionIdNormalizer` for more.
190
+ */
191
+ sessionIdNormalizer = new SessionIdNormalizer_js_1.SessionIdNormalizer();
192
+ /**
193
+ * Contains entries for cluster base UUIDs and override strings (both local and final).
194
+ * As a performance optimization, entries for finalized strings also include the containing cluster object.
195
+ * This can be viewed as three separate tables: the inverse table for `localOverrides`, the inverse table for the union of all
196
+ * the overrides of the clusters in `finalIdToCluster`, and the inverse lookup of cluster base UUIDs to their clusters.
197
+ * This is unified as a performance optimization, as the common case does not have overridden IDs. It is a btree due to the need
198
+ * to make range queries.
199
+ */
200
+ clustersAndOverridesInversion = new sorted_btree_es6_1.BTree(undefined, Common_js_1.compareStrings);
201
+ /**
202
+ * Maps the first final ID in a cluster to its owning cluster.
203
+ * Can be searched in O(log n) to determine clusters for any final ID.
204
+ */
205
+ finalIdToCluster = new AppendOnlySortedMap_js_1.AppendOnlySortedMap(Common_js_1.compareFiniteNumbers);
206
+ logger;
137
207
  /**
138
208
  * @param localSessionId - the `IdCompressor`'s current local session ID.
139
209
  * @param reservedIdCount - the number of IDs that will be known by this compressor without relying on consensus.
@@ -148,59 +218,6 @@ class IdCompressor {
148
218
  constructor(localSessionId, reservedIdCount, attributionId, logger) {
149
219
  this.localSessionId = localSessionId;
150
220
  this.reservedIdCount = reservedIdCount;
151
- /**
152
- * Trivially reach consensus on default cluster size and reserved IDs.
153
- * These initial values must *NOT* change without careful consideration to compatibility.
154
- */
155
- this.newClusterCapacity = exports.defaultClusterCapacity;
156
- /**
157
- * Session ID -\> data about the session's current cluster.
158
- * Sessions are mutable, and thus should only be created via `createSession`.
159
- */
160
- this.sessions = new Map();
161
- /**
162
- * The base final ID of the next cluster to be created.
163
- */
164
- this.nextClusterBaseFinalId = 0;
165
- /**
166
- * Total number of IDs created locally during the current session.
167
- */
168
- this.localIdCount = 0;
169
- /**
170
- * Maps local IDs to override strings. This will contain an entry for every override assigned to a local ID generated during
171
- * the current session, and retains entries for the lifetime of this compressor.
172
- */
173
- this.localOverrides = new AppendOnlySortedMap_js_1.AppendOnlySortedMap(Common_js_1.compareFiniteNumbersReversed);
174
- /**
175
- * Maps local IDs to the final ID they are associated with (if any), and maps final IDs to the corresponding local ID (if any).
176
- * This is used to efficiently compute normalization. This map can be thought of as mapping ranges of "optimistic uncertainty"
177
- * (local IDs) to the result of consensus (reserved ranges of final IDs, a.k.a. clusters). Any given range of local IDs
178
- * does not necessarily span an entire cluster, as some session-space IDs may be allocated *after* a cluster has been allocated
179
- * but before it is full. In this case, there is no uncertainty, as the range of final IDs was reserved when the cluster was created.
180
- * However, there is always a range of local IDs with size \>= 1 associated with the beginning of every cluster, as clusters are only
181
- * created *after* they are needed and thus there is some period of uncertainty after local IDs have been handed out but before the
182
- * range containing them has been finalized. There may also be ranges of local IDs that do not start at the beginning of a
183
- * cluster; this happens when a cluster is expanded instead of allocating a new one.
184
- * Additionally, session space IDs associated with an override string will also always be local IDs, because there is uncertainty as
185
- * to whether another client simultaneously allocated the same override and could get sequenced first (a.k.a. unification) and its
186
- * final ID would be associated with that override.
187
- * See `SessionIdNormalizer` for more.
188
- */
189
- this.sessionIdNormalizer = new SessionIdNormalizer_js_1.SessionIdNormalizer();
190
- /**
191
- * Contains entries for cluster base UUIDs and override strings (both local and final).
192
- * As a performance optimization, entries for finalized strings also include the containing cluster object.
193
- * This can be viewed as three separate tables: the inverse table for `localOverrides`, the inverse table for the union of all
194
- * the overrides of the clusters in `finalIdToCluster`, and the inverse lookup of cluster base UUIDs to their clusters.
195
- * This is unified as a performance optimization, as the common case does not have overridden IDs. It is a btree due to the need
196
- * to make range queries.
197
- */
198
- this.clustersAndOverridesInversion = new sorted_btree_es6_1.BTree(undefined, Common_js_1.compareStrings);
199
- /**
200
- * Maps the first final ID in a cluster to its owning cluster.
201
- * Can be searched in O(log n) to determine clusters for any final ID.
202
- */
203
- this.finalIdToCluster = new AppendOnlySortedMap_js_1.AppendOnlySortedMap(Common_js_1.compareFiniteNumbers);
204
221
  (0, internal_1.assert)(reservedIdCount >= 0, 0x642 /* reservedIdCount must be non-negative */);
205
222
  if (attributionId !== undefined) {
206
223
  (0, UuidUtilities_js_1.assertIsUuidString)(attributionId);
@@ -1357,10 +1374,6 @@ class IdCompressor {
1357
1374
  }
1358
1375
  }
1359
1376
  exports.IdCompressor = IdCompressor;
1360
- /**
1361
- * Max allowed cluster size
1362
- */
1363
- IdCompressor.maxClusterSize = 2 ** 20;
1364
1377
  /**
1365
1378
  * The version of `IdCompressor` that is currently persisted.
1366
1379
  */
@@ -1371,7 +1384,6 @@ const currentWrittenVersion = '0.0.1';
1371
1384
  function hasOngoingSession(serialized) {
1372
1385
  return serialized.localSessionIndex !== undefined;
1373
1386
  }
1374
- exports.hasOngoingSession = hasOngoingSession;
1375
1387
  function deserializeCluster(serializedCluster) {
1376
1388
  const [sessionIndex, capacity, countOrOverrides, overrides] = serializedCluster;
1377
1389
  const hasCount = typeof countOrOverrides === 'number';