@fluidframework/id-compressor 2.0.0-rc.1.0.4 → 2.0.0-rc.2.0.0

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 (264) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +5 -5
  2. package/{.mocharc.js → .mocharc.cjs} +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
  5. package/api-extractor-lint.json +1 -1
  6. package/api-extractor.json +1 -1
  7. package/api-report/id-compressor.api.md +5 -42
  8. package/dist/finalSpace.d.ts +2 -2
  9. package/dist/finalSpace.d.ts.map +1 -1
  10. package/dist/finalSpace.js +4 -4
  11. package/dist/finalSpace.js.map +1 -1
  12. package/dist/id-compressor-alpha.d.ts +117 -112
  13. package/dist/id-compressor-beta.d.ts +84 -77
  14. package/dist/id-compressor-public.d.ts +84 -77
  15. package/dist/id-compressor-untrimmed.d.ts +117 -112
  16. package/dist/idCompressor.d.ts +15 -19
  17. package/dist/idCompressor.d.ts.map +1 -1
  18. package/dist/idCompressor.js +107 -94
  19. package/dist/idCompressor.js.map +1 -1
  20. package/dist/identifiers.d.ts +1 -1
  21. package/dist/identifiers.d.ts.map +1 -1
  22. package/dist/identifiers.js.map +1 -1
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +9 -10
  26. package/dist/index.js.map +1 -1
  27. package/dist/package.json +3 -0
  28. package/dist/packageVersion.d.ts +1 -1
  29. package/dist/packageVersion.js +1 -1
  30. package/dist/packageVersion.js.map +1 -1
  31. package/dist/persistanceUtilities.d.ts +1 -1
  32. package/dist/persistanceUtilities.d.ts.map +1 -1
  33. package/dist/persistanceUtilities.js.map +1 -1
  34. package/dist/sessionSpaceNormalizer.d.ts +2 -2
  35. package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
  36. package/dist/sessionSpaceNormalizer.js +4 -4
  37. package/dist/sessionSpaceNormalizer.js.map +1 -1
  38. package/dist/sessions.d.ts +2 -2
  39. package/dist/sessions.d.ts.map +1 -1
  40. package/dist/sessions.js +12 -12
  41. package/dist/sessions.js.map +1 -1
  42. package/dist/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  43. package/dist/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  44. package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  45. package/dist/test/appendOnlySortedMap.spec.d.ts +6 -0
  46. package/dist/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  47. package/dist/test/appendOnlySortedMap.spec.js.map +1 -0
  48. package/dist/test/idCompressor.perf.spec.d.ts +6 -0
  49. package/dist/test/idCompressor.perf.spec.d.ts.map +1 -0
  50. package/dist/test/idCompressor.perf.spec.js.map +1 -0
  51. package/dist/test/idCompressor.spec.d.ts +6 -0
  52. package/dist/test/idCompressor.spec.d.ts.map +1 -0
  53. package/dist/test/idCompressor.spec.js.map +1 -0
  54. package/dist/test/idCompressorTestUtilities.d.ts +245 -0
  55. package/dist/test/idCompressorTestUtilities.d.ts.map +1 -0
  56. package/dist/test/idCompressorTestUtilities.js +589 -0
  57. package/dist/test/idCompressorTestUtilities.js.map +1 -0
  58. package/dist/test/index.d.ts +9 -0
  59. package/dist/test/index.d.ts.map +1 -0
  60. package/dist/test/index.js +13 -0
  61. package/dist/test/index.js.map +1 -0
  62. package/dist/test/numericUuid.spec.d.ts +6 -0
  63. package/dist/test/numericUuid.spec.d.ts.map +1 -0
  64. package/dist/test/numericUuid.spec.js.map +1 -0
  65. package/dist/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  66. package/dist/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  67. package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -0
  68. package/dist/test/snapshots/dirname.cjs +16 -0
  69. package/dist/test/snapshots/dirname.cjs.map +1 -0
  70. package/dist/test/snapshots/dirname.d.cts +6 -0
  71. package/dist/test/snapshots/dirname.d.cts.map +1 -0
  72. package/{lib/types/idCompressor.mjs → dist/test/snapshots/summary.spec.d.ts} +1 -1
  73. package/dist/test/snapshots/summary.spec.d.ts.map +1 -0
  74. package/dist/test/snapshots/summary.spec.js.map +1 -0
  75. package/dist/test/testCommon.d.ts +90 -0
  76. package/dist/test/testCommon.d.ts.map +1 -0
  77. package/dist/test/testCommon.js +90 -0
  78. package/dist/test/testCommon.js.map +1 -0
  79. package/dist/tsdoc-metadata.json +1 -1
  80. package/dist/types/idCompressor.d.ts +134 -67
  81. package/dist/types/idCompressor.d.ts.map +1 -1
  82. package/dist/types/idCompressor.js.map +1 -1
  83. package/dist/types/index.d.ts +3 -3
  84. package/dist/types/index.d.ts.map +1 -1
  85. package/dist/types/index.js.map +1 -1
  86. package/dist/types/persisted-types/0.0.1.d.ts +1 -1
  87. package/dist/types/persisted-types/0.0.1.d.ts.map +1 -1
  88. package/dist/types/persisted-types/0.0.1.js.map +1 -1
  89. package/dist/types/persisted-types/index.d.ts +1 -1
  90. package/dist/types/persisted-types/index.d.ts.map +1 -1
  91. package/dist/types/persisted-types/index.js.map +1 -1
  92. package/dist/utilities.d.ts +2 -2
  93. package/dist/utilities.d.ts.map +1 -1
  94. package/dist/utilities.js.map +1 -1
  95. package/lib/{appendOnlySortedMap.d.mts → appendOnlySortedMap.d.ts} +1 -1
  96. package/lib/appendOnlySortedMap.d.ts.map +1 -0
  97. package/lib/{appendOnlySortedMap.mjs → appendOnlySortedMap.js} +3 -1
  98. package/lib/appendOnlySortedMap.js.map +1 -0
  99. package/lib/{finalSpace.d.mts → finalSpace.d.ts} +3 -3
  100. package/lib/finalSpace.d.ts.map +1 -0
  101. package/lib/{finalSpace.mjs → finalSpace.js} +2 -2
  102. package/lib/finalSpace.js.map +1 -0
  103. package/lib/{id-compressor-alpha.d.mts → id-compressor-alpha.d.ts} +117 -112
  104. package/lib/id-compressor-beta.d.ts +179 -0
  105. package/lib/id-compressor-public.d.ts +179 -0
  106. package/lib/{id-compressor-untrimmed.d.mts → id-compressor-untrimmed.d.ts} +117 -112
  107. package/lib/{idCompressor.d.mts → idCompressor.d.ts} +16 -20
  108. package/lib/idCompressor.d.ts.map +1 -0
  109. package/lib/{idCompressor.mjs → idCompressor.js} +54 -41
  110. package/lib/idCompressor.js.map +1 -0
  111. package/lib/{identifiers.d.mts → identifiers.d.ts} +2 -2
  112. package/lib/identifiers.d.ts.map +1 -0
  113. package/lib/{identifiers.mjs → identifiers.js} +1 -1
  114. package/lib/identifiers.js.map +1 -0
  115. package/lib/{index.d.mts → index.d.ts} +7 -4
  116. package/lib/index.d.ts.map +1 -0
  117. package/lib/index.js +10 -0
  118. package/lib/index.js.map +1 -0
  119. package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
  120. package/lib/packageVersion.d.ts.map +1 -0
  121. package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
  122. package/lib/packageVersion.js.map +1 -0
  123. package/lib/{persistanceUtilities.d.mts → persistanceUtilities.d.ts} +2 -2
  124. package/lib/persistanceUtilities.d.ts.map +1 -0
  125. package/lib/{persistanceUtilities.mjs → persistanceUtilities.js} +1 -1
  126. package/lib/persistanceUtilities.js.map +1 -0
  127. package/lib/{sessionSpaceNormalizer.d.mts → sessionSpaceNormalizer.d.ts} +3 -3
  128. package/lib/sessionSpaceNormalizer.d.ts.map +1 -0
  129. package/lib/{sessionSpaceNormalizer.mjs → sessionSpaceNormalizer.js} +3 -3
  130. package/lib/sessionSpaceNormalizer.js.map +1 -0
  131. package/lib/{sessions.d.mts → sessions.d.ts} +3 -3
  132. package/lib/sessions.d.ts.map +1 -0
  133. package/lib/{sessions.mjs → sessions.js} +2 -2
  134. package/lib/sessions.js.map +1 -0
  135. package/lib/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  136. package/lib/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  137. package/lib/test/appendOnlySortedMap.perf.spec.js +49 -0
  138. package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  139. package/lib/test/appendOnlySortedMap.spec.d.ts +6 -0
  140. package/lib/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  141. package/lib/test/appendOnlySortedMap.spec.js +166 -0
  142. package/lib/test/appendOnlySortedMap.spec.js.map +1 -0
  143. package/lib/test/idCompressor.perf.spec.d.ts +6 -0
  144. package/lib/test/idCompressor.perf.spec.d.ts.map +1 -0
  145. package/lib/test/idCompressor.perf.spec.js +281 -0
  146. package/lib/test/idCompressor.perf.spec.js.map +1 -0
  147. package/lib/test/idCompressor.spec.d.ts +6 -0
  148. package/lib/test/idCompressor.spec.d.ts.map +1 -0
  149. package/lib/test/idCompressor.spec.js +953 -0
  150. package/lib/test/idCompressor.spec.js.map +1 -0
  151. package/lib/test/idCompressorTestUtilities.d.ts +245 -0
  152. package/lib/test/idCompressorTestUtilities.d.ts.map +1 -0
  153. package/lib/test/idCompressorTestUtilities.js +576 -0
  154. package/lib/test/idCompressorTestUtilities.js.map +1 -0
  155. package/lib/test/index.d.ts +9 -0
  156. package/lib/test/index.d.ts.map +1 -0
  157. package/lib/test/index.js +9 -0
  158. package/lib/test/index.js.map +1 -0
  159. package/lib/test/numericUuid.spec.d.ts +6 -0
  160. package/lib/test/numericUuid.spec.d.ts.map +1 -0
  161. package/lib/test/numericUuid.spec.js +74 -0
  162. package/lib/test/numericUuid.spec.js.map +1 -0
  163. package/lib/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  164. package/lib/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  165. package/lib/test/sessionSpaceNormalizer.spec.js +43 -0
  166. package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -0
  167. package/lib/test/snapshots/dirname.cjs +16 -0
  168. package/lib/test/snapshots/dirname.cjs.map +1 -0
  169. package/lib/test/snapshots/dirname.d.cts +6 -0
  170. package/lib/test/snapshots/dirname.d.cts.map +1 -0
  171. package/lib/test/snapshots/summary.spec.d.ts +6 -0
  172. package/lib/test/snapshots/summary.spec.d.ts.map +1 -0
  173. package/lib/test/snapshots/summary.spec.js +127 -0
  174. package/lib/test/snapshots/summary.spec.js.map +1 -0
  175. package/lib/test/testCommon.d.ts +90 -0
  176. package/lib/test/testCommon.d.ts.map +1 -0
  177. package/lib/test/testCommon.js +80 -0
  178. package/lib/test/testCommon.js.map +1 -0
  179. package/lib/types/{idCompressor.d.mts → idCompressor.d.ts} +135 -68
  180. package/lib/types/idCompressor.d.ts.map +1 -0
  181. package/lib/types/{identifiers.mjs → idCompressor.js} +1 -1
  182. package/lib/types/idCompressor.js.map +1 -0
  183. package/lib/types/{identifiers.d.mts → identifiers.d.ts} +1 -1
  184. package/lib/types/identifiers.d.ts.map +1 -0
  185. package/lib/types/identifiers.js +6 -0
  186. package/lib/types/identifiers.js.map +1 -0
  187. package/lib/types/{index.d.mts → index.d.ts} +4 -4
  188. package/lib/types/index.d.ts.map +1 -0
  189. package/lib/types/{persisted-types/0.0.1.mjs → index.js} +1 -1
  190. package/lib/types/index.js.map +1 -0
  191. package/lib/types/persisted-types/{0.0.1.d.mts → 0.0.1.d.ts} +2 -2
  192. package/lib/types/persisted-types/0.0.1.d.ts.map +1 -0
  193. package/lib/types/persisted-types/{index.mjs → 0.0.1.js} +1 -1
  194. package/lib/types/persisted-types/0.0.1.js.map +1 -0
  195. package/lib/types/persisted-types/{index.d.mts → index.d.ts} +2 -2
  196. package/lib/types/persisted-types/index.d.ts.map +1 -0
  197. package/lib/types/{index.mjs → persisted-types/index.js} +1 -1
  198. package/lib/types/persisted-types/index.js.map +1 -0
  199. package/lib/{utilities.d.mts → utilities.d.ts} +3 -3
  200. package/lib/utilities.d.ts.map +1 -0
  201. package/lib/{utilities.mjs → utilities.js} +2 -1
  202. package/lib/utilities.js.map +1 -0
  203. package/package.json +87 -21
  204. package/src/finalSpace.ts +2 -2
  205. package/src/idCompressor.ts +75 -59
  206. package/src/identifiers.ts +1 -1
  207. package/src/index.ts +3 -3
  208. package/src/packageVersion.ts +1 -1
  209. package/src/persistanceUtilities.ts +1 -1
  210. package/src/sessionSpaceNormalizer.ts +3 -3
  211. package/src/sessions.ts +3 -3
  212. package/src/test/idCompressorTestUtilities.ts +921 -0
  213. package/src/test/index.ts +10 -0
  214. package/src/test/snapshots/dirname.cts +13 -0
  215. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client +1 -0
  216. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client-client2 +1 -0
  217. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients +1 -0
  218. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients-client2 +1 -0
  219. package/src/test/snapshots/files/empty-compressor-summary +1 -0
  220. package/src/test/snapshots/files/expansion-semantics +1 -0
  221. package/src/test/snapshots/files/expansion-semantics-client2 +1 -0
  222. package/src/test/testCommon.ts +143 -0
  223. package/src/test/tsconfig.cjs.json +12 -0
  224. package/src/test/tsconfig.json +20 -0
  225. package/src/types/idCompressor.ts +147 -72
  226. package/src/types/index.ts +8 -3
  227. package/src/types/persisted-types/0.0.1.ts +1 -1
  228. package/src/types/persisted-types/index.ts +1 -1
  229. package/src/utilities.ts +2 -2
  230. package/tsconfig.cjs.json +7 -0
  231. package/tsconfig.json +2 -5
  232. package/lib/appendOnlySortedMap.d.mts.map +0 -1
  233. package/lib/appendOnlySortedMap.mjs.map +0 -1
  234. package/lib/finalSpace.d.mts.map +0 -1
  235. package/lib/finalSpace.mjs.map +0 -1
  236. package/lib/id-compressor-beta.d.mts +0 -172
  237. package/lib/id-compressor-public.d.mts +0 -172
  238. package/lib/idCompressor.d.mts.map +0 -1
  239. package/lib/idCompressor.mjs.map +0 -1
  240. package/lib/identifiers.d.mts.map +0 -1
  241. package/lib/identifiers.mjs.map +0 -1
  242. package/lib/index.d.mts.map +0 -1
  243. package/lib/index.mjs +0 -7
  244. package/lib/index.mjs.map +0 -1
  245. package/lib/packageVersion.d.mts.map +0 -1
  246. package/lib/packageVersion.mjs.map +0 -1
  247. package/lib/persistanceUtilities.d.mts.map +0 -1
  248. package/lib/persistanceUtilities.mjs.map +0 -1
  249. package/lib/sessionSpaceNormalizer.d.mts.map +0 -1
  250. package/lib/sessionSpaceNormalizer.mjs.map +0 -1
  251. package/lib/sessions.d.mts.map +0 -1
  252. package/lib/sessions.mjs.map +0 -1
  253. package/lib/types/idCompressor.d.mts.map +0 -1
  254. package/lib/types/idCompressor.mjs.map +0 -1
  255. package/lib/types/identifiers.d.mts.map +0 -1
  256. package/lib/types/identifiers.mjs.map +0 -1
  257. package/lib/types/index.d.mts.map +0 -1
  258. package/lib/types/index.mjs.map +0 -1
  259. package/lib/types/persisted-types/0.0.1.d.mts.map +0 -1
  260. package/lib/types/persisted-types/0.0.1.mjs.map +0 -1
  261. package/lib/types/persisted-types/index.d.mts.map +0 -1
  262. package/lib/types/persisted-types/index.mjs.map +0 -1
  263. package/lib/utilities.d.mts.map +0 -1
  264. package/lib/utilities.mjs.map +0 -1
@@ -2,7 +2,10 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { createIdCompressor, deserializeIdCompressor, IdCompressor } from "./idCompressor.mjs";
6
- export { createSessionId, assertIsStableId, generateStableId, isStableId } from "./utilities.mjs";
7
- export { IIdCompressorCore, IIdCompressor, SerializedIdCompressor, SerializedIdCompressorWithOngoingSession, SerializedIdCompressorWithNoSession, SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId, IdCreationRange, } from "./types/index.mjs";
8
- //# sourceMappingURL=index.d.mts.map
5
+ /**
6
+ * Exports for `id-compressor`
7
+ */
8
+ export { createIdCompressor, deserializeIdCompressor } from "./idCompressor.js";
9
+ export { createSessionId, assertIsStableId, generateStableId, isStableId } from "./utilities.js";
10
+ export { IIdCompressorCore, IIdCompressor, SerializedIdCompressor, SerializedIdCompressorWithOngoingSession, SerializedIdCompressorWithNoSession, SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId, IdCreationRange, } from "./types/index.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,wCAAwC,EACxC,mCAAmC,EACnC,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,eAAe,GACf,MAAM,kBAAkB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Exports for `id-compressor`
7
+ */
8
+ export { createIdCompressor, deserializeIdCompressor } from "./idCompressor.js";
9
+ export { createSessionId, assertIsStableId, generateStableId, isStableId } from "./utilities.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Exports for `id-compressor`\n */\n\nexport { createIdCompressor, deserializeIdCompressor } from \"./idCompressor.js\";\nexport { createSessionId, assertIsStableId, generateStableId, isStableId } from \"./utilities.js\";\nexport {\n\tIIdCompressorCore,\n\tIIdCompressor,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithOngoingSession,\n\tSerializedIdCompressorWithNoSession,\n\tSessionSpaceCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n\tStableId,\n\tIdCreationRange,\n} from \"./types/index.js\";\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/id-compressor";
8
- export declare const pkgVersion = "2.0.0-rc.1.0.4";
9
- //# sourceMappingURL=packageVersion.d.mts.map
8
+ export declare const pkgVersion = "2.0.0-rc.2.0.0";
9
+ //# sourceMappingURL=packageVersion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,kCAAkC,CAAC;AACvD,eAAO,MAAM,UAAU,mBAAmB,CAAC"}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/id-compressor";
8
- export const pkgVersion = "2.0.0-rc.1.0.4";
9
- //# sourceMappingURL=packageVersion.mjs.map
8
+ export const pkgVersion = "2.0.0-rc.2.0.0";
9
+ //# sourceMappingURL=packageVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,+BAA+B,CAAC;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/id-compressor\";\nexport const pkgVersion = \"2.0.0-rc.2.0.0\";\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { NumericUuid } from "./identifiers.mjs";
5
+ import { NumericUuid } from "./identifiers.js";
6
6
  export declare function writeNumber(buffer: Float64Array, index: number, value: number): number;
7
7
  export declare function writeNumericUuid(buffer: BigUint64Array, index: number, value: NumericUuid): number;
8
8
  export declare function writeBoolean(buffer: Float64Array, index: number, value: boolean): number;
@@ -19,4 +19,4 @@ export interface Index {
19
19
  export declare function readNumber(index: Index): number;
20
20
  export declare function readNumericUuid(index: Index): NumericUuid;
21
21
  export declare function readBoolean(index: Index): boolean;
22
- //# sourceMappingURL=persistanceUtilities.d.mts.map
22
+ //# sourceMappingURL=persistanceUtilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistanceUtilities.d.ts","sourceRoot":"","sources":["../src/persistanceUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAK/C,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,GAChB,MAAM,CAIR;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAExF;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACrB,WAAW,EAAE,YAAY,CAAC;IAC1B,UAAU,EAAE,cAAc,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAI/C;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAMzD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEjD"}
@@ -31,4 +31,4 @@ export function readNumericUuid(index) {
31
31
  export function readBoolean(index) {
32
32
  return readNumber(index) === 1;
33
33
  }
34
- //# sourceMappingURL=persistanceUtilities.mjs.map
34
+ //# sourceMappingURL=persistanceUtilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistanceUtilities.js","sourceRoot":"","sources":["../src/persistanceUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACjD,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAE7B,MAAM,UAAU,WAAW,CAAC,MAAoB,EAAE,KAAa,EAAE,KAAa;IAC7E,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACtB,OAAO,KAAK,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC/B,MAAsB,EACtB,KAAa,EACb,KAAkB;IAElB,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC;IACvC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,4BAA4B;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,KAAa,EAAE,KAAc;IAC/E,OAAO,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC;AAaD,MAAM,UAAU,UAAU,CAAC,KAAY;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACjB,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,GAAG,SAAS,CAAC;IACnD,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACjB,OAAO,KAAoB,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { NumericUuid } from \"./identifiers.js\";\n\nconst halfNumeric = BigInt(\"0xFFFFFFFFFFFFFFFF\");\nconst sixtyFour = BigInt(64);\n\nexport function writeNumber(buffer: Float64Array, index: number, value: number): number {\n\tbuffer[index] = value;\n\treturn index + 1;\n}\n\nexport function writeNumericUuid(\n\tbuffer: BigUint64Array,\n\tindex: number,\n\tvalue: NumericUuid,\n): number {\n\tbuffer[index] = value & halfNumeric;\n\tbuffer[index + 1] = value >> sixtyFour;\n\treturn index + 2; // UUID values are 16 bytes.\n}\n\nexport function writeBoolean(buffer: Float64Array, index: number, value: boolean): number {\n\treturn writeNumber(buffer, index, value ? 1 : 0);\n}\n\n/**\n * Helper type to allow returning a value when reading as well as incrementing an index to make\n * deserialization easier.\n * Should be constructed with two views of the same buffer and index set to 0.\n */\nexport interface Index {\n\tbufferFloat: Float64Array;\n\tbufferUint: BigUint64Array;\n\tindex: number;\n}\n\nexport function readNumber(index: Index): number {\n\tconst value = index.bufferFloat[index.index];\n\tindex.index += 1;\n\treturn value;\n}\n\nexport function readNumericUuid(index: Index): NumericUuid {\n\tconst lowerHalf = index.bufferUint[index.index];\n\tconst upperHalf = index.bufferUint[index.index + 1];\n\tconst value = (upperHalf << sixtyFour) | lowerHalf;\n\tindex.index += 2;\n\treturn value as NumericUuid;\n}\n\nexport function readBoolean(index: Index): boolean {\n\treturn readNumber(index) === 1;\n}\n"]}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { AppendOnlySortedMap } from "./appendOnlySortedMap.mjs";
6
- import { LocalCompressedId } from "./identifiers.mjs";
5
+ import { AppendOnlySortedMap } from "./appendOnlySortedMap.js";
6
+ import { LocalCompressedId } from "./identifiers.js";
7
7
  /**
8
8
  * The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.
9
9
  * More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific
@@ -43,4 +43,4 @@ export declare class SessionSpaceNormalizer {
43
43
  contains(query: LocalCompressedId): boolean;
44
44
  equals(other: SessionSpaceNormalizer): boolean;
45
45
  }
46
- //# sourceMappingURL=sessionSpaceNormalizer.d.mts.map
46
+ //# sourceMappingURL=sessionSpaceNormalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionSpaceNormalizer.d.ts","sourceRoot":"","sources":["../src/sessionSpaceNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,sBAAsB;IAGlC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiE;IAE/F,IAAW,QAAQ,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAEnF;IAEM,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAcxD,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO;IAY3C,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;CAMrD"}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { AppendOnlySortedMap } from "./appendOnlySortedMap.mjs";
6
- import { compareFiniteNumbers, genCountFromLocalId } from "./utilities.mjs";
5
+ import { AppendOnlySortedMap } from "./appendOnlySortedMap.js";
6
+ import { compareFiniteNumbers, genCountFromLocalId } from "./utilities.js";
7
7
  /**
8
8
  * The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.
9
9
  * More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific
@@ -73,4 +73,4 @@ export class SessionSpaceNormalizer {
73
73
  return this.localIdRanges.equals(other.localIdRanges, (countA, countB) => countA === countB);
74
74
  }
75
75
  }
76
- //# sourceMappingURL=sessionSpaceNormalizer.mjs.map
76
+ //# sourceMappingURL=sessionSpaceNormalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionSpaceNormalizer.js","sourceRoot":"","sources":["../src/sessionSpaceNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,sBAAsB;IAAnC;QACC,qHAAqH;QACrH,mFAAmF;QAClE,kBAAa,GAAG,IAAI,mBAAmB,CAAiB,oBAAoB,CAAC,CAAC;IAsChG,CAAC;IApCA,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IAEM,aAAa,CAAC,YAAoB,EAAE,KAAa;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,KAAK,SAAS,EAAE;YACvB,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;YACvC,sFAAsF;YACtF,yDAAyD;YACzD,IAAI,YAAY,GAAG,SAAS,KAAK,YAAY,EAAE;gBAC9C,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,EAAE,SAAS,GAAG,KAAK,CAAC,CAAC;gBAChE,OAAO;aACP;SACD;QACD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;IAEM,QAAQ,CAAC,KAAwB;QACvC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,eAAe,KAAK,SAAS,EAAE;YAClC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,eAAe,CAAC;YAC9C,IAAI,QAAQ,IAAI,YAAY,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE;gBAC3C,OAAO,IAAI,CAAC;aACZ;SACD;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,KAA6B;QAC1C,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAC/B,KAAK,CAAC,aAAa,EACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,CACrC,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AppendOnlySortedMap } from \"./appendOnlySortedMap.js\";\nimport { LocalCompressedId } from \"./identifiers.js\";\nimport { compareFiniteNumbers, genCountFromLocalId } from \"./utilities.js\";\n\n/**\n * The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.\n * More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific\n * ID was produced by the local session. This information can be used to determine whether the nth ID created by the local session\n * was produced as a local ID (negative) or a final ID (positive).\n *\n * The local and final forms of IDs made by a session can be thought of as two equal-length sparse arrays, aligned such\n * that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.\n * Below is an example to illustrate how various mappings can arise:\n *\n * ```\n * +- Creation Index\n * / +- Locals\n * / / +- Finals\n * / / /\n * ---+-----+----\n * 0 | -1 | 0 -|___ Two IDs are allocated as locals since no cluster exists. A new cluster is created when acked.\n * 1 | -2 | 1 -|\n * 2 | | 2 -|\n * 3 | | 3 --|-- Three more IDs are allocated as finals eagerly since a cluster exists with available capacity.\n * 4 | | 4 -|\n * 5 | -6 | 10 ----- One ID is allocated as a local (it overflows the existing cluster) and a new cluster is created after ack.\n * 6 | | 11 ----- This ID (and the subsequent few) is allocated eagerly as a final ID into the existing cluster.\n * 7 | | 12\n * 8 | | 13\n * 9 | | 14\n * 10 | -11 | ----- The cluster is out of room, so a local ID is allocated. It has no corresponding final ID since it has not been acked.\n * ```\n *\n * This class stores the set of local IDs and thus their indices, as local IDs are essentially negative offsets from the first ID.\n * The form (local or final) of a given ID index (for example, the 5th ID made by the local session) can be deduced from this information.\n */\nexport class SessionSpaceNormalizer {\n\t// Run-length encoding of IDs that were generated as local IDs. They are stored as a list of tuples (genCount, count)\n\t// that are sorted on the genCount so that contains checks can use a binary search.\n\tprivate readonly localIdRanges = new AppendOnlySortedMap<number, number>(compareFiniteNumbers);\n\n\tpublic get idRanges(): Pick<AppendOnlySortedMap<number, number>, \"size\" | \"entries\"> {\n\t\treturn this.localIdRanges;\n\t}\n\n\tpublic addLocalRange(baseGenCount: number, count: number): void {\n\t\tconst last = this.localIdRanges.last();\n\t\tif (last !== undefined) {\n\t\t\tconst [lastGenCount, lastCount] = last;\n\t\t\t// Check to see if the added run of local IDs is contiguous with the last range added.\n\t\t\t// If it is, simply merge them (this is the common case).\n\t\t\tif (lastGenCount + lastCount === baseGenCount) {\n\t\t\t\tthis.localIdRanges.replaceLast(lastGenCount, lastCount + count);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.localIdRanges.append(baseGenCount, count);\n\t}\n\n\tpublic contains(query: LocalCompressedId): boolean {\n\t\tconst genCount = genCountFromLocalId(query);\n\t\tconst containingBlock = this.localIdRanges.getPairOrNextLower(genCount);\n\t\tif (containingBlock !== undefined) {\n\t\t\tconst [baseGenCount, count] = containingBlock;\n\t\t\tif (genCount <= baseGenCount + (count - 1)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic equals(other: SessionSpaceNormalizer): boolean {\n\t\treturn this.localIdRanges.equals(\n\t\t\tother.localIdRanges,\n\t\t\t(countA, countB) => countA === countB,\n\t\t);\n\t}\n}\n"]}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { SessionId, StableId } from "./types/index.mjs";
6
- import { FinalCompressedId, LocalCompressedId, NumericUuid } from "./identifiers.mjs";
5
+ import { SessionId, StableId } from "./types/index.js";
6
+ import { FinalCompressedId, LocalCompressedId, NumericUuid } from "./identifiers.js";
7
7
  /**
8
8
  * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).
9
9
  * This collection of all sessions comprises a distributed document's IDs.
@@ -112,4 +112,4 @@ export declare function lastAllocatedLocal(cluster: IdCluster): LocalCompressedI
112
112
  * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster
113
113
  */
114
114
  export declare function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId;
115
- //# sourceMappingURL=sessions.d.mts.map
115
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 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B,GAC5B,iBAAiB,CAOnB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,GAAG,iBAAiB,CAExE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,GAAG,iBAAiB,CAExE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,GAAG,iBAAiB,CAExE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,GAAG,iBAAiB,CAExE"}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { BTree } from "@tylerbu/sorted-btree-es6";
6
6
  import { assert } from "@fluidframework/core-utils";
7
- import { compareBigints, localIdFromGenCount, genCountFromLocalId, numericUuidFromStableId, stableIdFromNumericUuid, subtractNumericUuids, offsetNumericUuid, } from "./utilities.mjs";
7
+ import { compareBigints, localIdFromGenCount, genCountFromLocalId, numericUuidFromStableId, stableIdFromNumericUuid, subtractNumericUuids, offsetNumericUuid, } from "./utilities.js";
8
8
  /**
9
9
  * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).
10
10
  * This collection of all sessions comprises a distributed document's IDs.
@@ -287,4 +287,4 @@ export function lastAllocatedLocal(cluster) {
287
287
  export function lastFinalizedLocal(cluster) {
288
288
  return (cluster.baseLocalId - (cluster.count - 1));
289
289
  }
290
- //# sourceMappingURL=sessions.mjs.map
290
+ //# sourceMappingURL=sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,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D,CAAC;IACF,MAAM,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACrD,OAAO,CAAC,OAAO,CAAC,WAAW,GAAG,UAAU,CAAsB,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BTree } from \"@tylerbu/sorted-btree-es6\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { SessionId, StableId } from \"./types/index.js\";\nimport {\n\tcompareBigints,\n\tlocalIdFromGenCount,\n\tgenCountFromLocalId,\n\tnumericUuidFromStableId,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n\toffsetNumericUuid,\n} from \"./utilities.js\";\nimport { FinalCompressedId, LocalCompressedId, NumericUuid } from \"./identifiers.js\";\n\n/**\n * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).\n * This collection of all sessions comprises a distributed document's IDs.\n */\nexport class Sessions {\n\t// A range-queryable store of all sessions. A btree is used as it solves the predecessor problem for any given UUID, allowing\n\t// us to quickly find the session that may have produced it.\n\tprivate readonly uuidSpace = new BTree<NumericUuid, Session>(undefined, compareBigints);\n\t// A fast lookup table from session ID to the session object, used to avoid accessing the slower btree\n\tprivate readonly sessionCache = new Map<SessionId, Session>();\n\n\tpublic constructor(sessions?: [sessionBase: NumericUuid, session: Session][]) {\n\t\tif (sessions !== undefined) {\n\t\t\t// bulk load path\n\t\t\tfor (const [numeric, session] of sessions) {\n\t\t\t\tthis.sessionCache.set(stableIdFromNumericUuid(numeric) as SessionId, session);\n\t\t\t}\n\t\t\tthis.uuidSpace = new BTree(sessions, compareBigints);\n\t\t\tif (\n\t\t\t\tthis.sessionCache.size !== sessions.length ||\n\t\t\t\tsessions.length !== this.uuidSpace.size\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Cannot resume existing session.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic sessions(): IterableIterator<Session> {\n\t\treturn this.sessionCache.values();\n\t}\n\n\tpublic getOrCreate(sessionId: SessionId): Session {\n\t\tconst existing = this.sessionCache.get(sessionId);\n\t\tif (existing !== undefined) {\n\t\t\treturn existing;\n\t\t}\n\t\tconst session = new Session(sessionId);\n\t\tassert(\n\t\t\tthis.uuidSpace.set(session.sessionUuid, session),\n\t\t\t0x760 /* Duplicate session in map. */,\n\t\t);\n\t\tthis.sessionCache.set(sessionId, session);\n\t\treturn session;\n\t}\n\n\tpublic get(sessionId: SessionId): Session | undefined {\n\t\treturn this.sessionCache.get(sessionId);\n\t}\n\n\tpublic getContainingCluster(\n\t\tquery: StableId,\n\t): [cluster: IdCluster, alignedLocal: LocalCompressedId] | undefined {\n\t\tconst numericStable = numericUuidFromStableId(query);\n\t\tconst possibleMatch = this.uuidSpace.getPairOrNextLower(numericStable);\n\t\tif (possibleMatch === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [_, session] = possibleMatch;\n\t\tconst numericDelta = subtractNumericUuids(numericStable, session.sessionUuid);\n\t\tif (numericDelta > Number.MAX_SAFE_INTEGER) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst alignedLocal = localIdFromGenCount(Number(numericDelta) + 1);\n\t\tconst containingCluster = session.getClusterByLocal(alignedLocal, true);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [containingCluster, alignedLocal];\n\t}\n\n\tpublic clusterCollides(cluster: IdCluster): boolean {\n\t\tconst { session: owningSession, baseLocalId, capacity } = cluster;\n\t\tconst clusterBaseNumeric = offsetNumericUuid(\n\t\t\towningSession.sessionUuid,\n\t\t\tgenCountFromLocalId(baseLocalId) - 1,\n\t\t);\n\t\tconst clusterMaxNumeric = offsetNumericUuid(clusterBaseNumeric, capacity - 1);\n\t\tlet closestMatch: [NumericUuid, Session] | undefined =\n\t\t\tthis.uuidSpace.getPairOrNextLower(clusterMaxNumeric);\n\t\t// Find the first session that is not the owner of this new cluster.\n\t\t// Once we have that, check to see if its cluster chain overlaps with the new cluster.\n\t\t// Consider the following diagram of UUID space:\n\t\t// Cluster chain A: |----------------------|\n\t\t// Cluster chain B: |----------|\n\t\t// Cluster chain C: |-------|\n\t\t// While it is true that when adding a cluster to chain C, we would find\n\t\t// the next lower session (which is B) and erroneously determine we do not collide\n\t\t// with any other session, but this situation is impossible to get into as B would\n\t\t// have detected that it collided with A (or the other way around, depending on ordering).\n\t\twhile (closestMatch !== undefined && closestMatch[1] === owningSession) {\n\t\t\tclosestMatch = this.uuidSpace.nextLowerPair(closestMatch[0]);\n\t\t}\n\t\tif (closestMatch === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [_, session] = closestMatch;\n\t\tassert(session !== owningSession, 0x761 /* Failed to attempt to detect collisions. */);\n\t\tconst lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// If the closest session is empty (the local session), then it is guaranteed (probabilistically) that there are no\n\t\t\t// non-empty sessions that have a cluster chain that starts prior to the empty session and collides with the cluster\n\t\t\t// we are checking, so we can return false.\n\t\t\treturn false;\n\t\t}\n\t\tconst lastAllocatedNumeric = offsetNumericUuid(\n\t\t\tsession.sessionUuid,\n\t\t\tgenCountFromLocalId(lastAllocatedLocal(lastCluster)) - 1,\n\t\t);\n\t\treturn lastAllocatedNumeric >= clusterBaseNumeric;\n\t}\n\n\tpublic equals(other: Sessions, includeLocalState: boolean): boolean {\n\t\tconst checkIsSubset = (sessionsA: Sessions, sessionsB: Sessions) => {\n\t\t\tconst first = sessionsA.sessions().next();\n\t\t\tconst firstSessionThis = first.done ? undefined : first.value;\n\t\t\tfor (const [stableId, session] of sessionsA.sessionCache.entries()) {\n\t\t\t\tconst otherSession = sessionsB.sessionCache.get(stableId);\n\t\t\t\tif (otherSession === undefined) {\n\t\t\t\t\tif (!session.isEmpty() || includeLocalState) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsession === firstSessionThis,\n\t\t\t\t\t\t0x762 /* The only non-empty session must be the local session. */,\n\t\t\t\t\t);\n\t\t\t\t} else if (!session.equals(otherSession)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\treturn checkIsSubset(this, other) && checkIsSubset(other, this);\n\t}\n}\n\n/**\n * The IDs created by a specific session, stored as a cluster chain to allow for fast conversions.\n */\nexport class Session {\n\t// All clusters created by this session, in creation order (thus sorted by base final and local ID).\n\tprivate readonly clusterChain: IdCluster[] = [];\n\t// The numeric form of the SessionId\n\tpublic readonly sessionUuid: NumericUuid;\n\n\tpublic constructor(sessionId: SessionId | NumericUuid) {\n\t\tthis.sessionUuid =\n\t\t\ttypeof sessionId === \"string\" ? numericUuidFromStableId(sessionId) : sessionId;\n\t}\n\n\t/**\n\t * Adds a new empty cluster to the cluster chain of this session.\n\t */\n\tpublic addNewCluster(\n\t\tbaseFinalId: FinalCompressedId,\n\t\tcapacity: number,\n\t\tcount: number,\n\t): IdCluster {\n\t\tconst lastCluster = this.getLastCluster();\n\t\tconst newCluster: IdCluster = {\n\t\t\tsession: this,\n\t\t\tbaseFinalId,\n\t\t\tbaseLocalId: (lastCluster === undefined\n\t\t\t\t? -1\n\t\t\t\t: lastAllocatedLocal(lastCluster) - 1) as LocalCompressedId,\n\t\t\tcapacity,\n\t\t\tcount,\n\t\t};\n\t\tthis.clusterChain.push(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.clusterChain.length === 0;\n\t}\n\n\t/**\n\t * Returns the last cluster in this session's cluster chain, if any.\n\t */\n\tpublic getLastCluster(): IdCluster | undefined {\n\t\treturn this.clusterChain[this.clusterChain.length - 1];\n\t}\n\n\t/**\n\t * Converts the local ID from this session to a final ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic tryConvertToFinal(\n\t\tsearchLocal: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): FinalCompressedId | undefined {\n\t\tconst containingCluster = this.getClusterByLocal(searchLocal, includeAllocated);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getAlignedFinal(containingCluster, searchLocal);\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied local ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic getClusterByLocal(\n\t\tlocalId: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): IdCluster | undefined {\n\t\tconst lastValidLocal: (cluster: IdCluster) => LocalCompressedId = includeAllocated\n\t\t\t? lastAllocatedLocal\n\t\t\t: lastFinalizedLocal;\n\t\tconst matchedCluster = Session.binarySearch(\n\t\t\tlocalId,\n\t\t\tthis.clusterChain,\n\t\t\t(local, cluster): number => {\n\t\t\t\tconst lastLocal = lastValidLocal(cluster);\n\t\t\t\tif (local < lastLocal) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (local > cluster.baseLocalId) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t\treturn matchedCluster;\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied final ID, if possible.\n\t */\n\tpublic getClusterByAllocatedFinal(final: FinalCompressedId): IdCluster | undefined {\n\t\treturn Session.getContainingCluster(final, this.clusterChain);\n\t}\n\n\t/**\n\t * Returns the cluster from the supplied cluster chain containing the supplied final ID, if possible.\n\t * `clusterChain` must be sorted by final/local base ID.\n\t */\n\tpublic static getContainingCluster(\n\t\tfinalId: FinalCompressedId,\n\t\tclusterChain: readonly IdCluster[],\n\t): IdCluster | undefined {\n\t\treturn Session.binarySearch(finalId, clusterChain, (final, cluster) => {\n\t\t\tconst lastFinal = lastAllocatedFinal(cluster);\n\t\t\tif (final < cluster.baseFinalId) {\n\t\t\t\treturn -1;\n\t\t\t} else if (final > lastFinal) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tstatic binarySearch<S, T>(\n\t\tsearch: S,\n\t\tarr: readonly T[],\n\t\tcomparator: (a: S, b: T) => number,\n\t): T | undefined {\n\t\tlet left = 0;\n\t\tlet right = arr.length - 1;\n\t\twhile (left <= right) {\n\t\t\tconst mid = Math.floor((left + right) / 2);\n\t\t\tconst c = comparator(search, arr[mid]);\n\t\t\tif (c === 0) {\n\t\t\t\treturn arr[mid]; // Found the target, return its index.\n\t\t\t} else if (c > 0) {\n\t\t\t\tleft = mid + 1; // Continue search on right half.\n\t\t\t} else {\n\t\t\t\tright = mid - 1; // Continue search on left half.\n\t\t\t}\n\t\t}\n\t\treturn undefined; // If we reach here, target is not in array.\n\t}\n\n\tpublic equals(other: Session): boolean {\n\t\tfor (let i = 0; i < this.clusterChain.length; i++) {\n\t\t\tif (!clustersEqual(this.clusterChain[i], other.clusterChain[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn this.sessionUuid === other.sessionUuid;\n\t}\n}\n\n/**\n * A cluster of final (sequenced via consensus), sequentially allocated compressed IDs.\n * A final ID in a cluster decompresses to a sequentially allocated UUID that is the result of adding its offset within\n * the cluster to base UUID for the session that created it.\n */\nexport interface IdCluster {\n\t/**\n\t * The session that created this cluster.\n\t */\n\treadonly session: Session;\n\n\t/**\n\t * The first final ID in the cluster.\n\t */\n\treadonly baseFinalId: FinalCompressedId;\n\n\t/**\n\t * The local ID aligned with `baseFinalId`.\n\t */\n\treadonly baseLocalId: LocalCompressedId;\n\n\t/**\n\t * The total number of final IDs reserved for allocation in the cluster.\n\t * Clusters are reserved in blocks as a performance optimization.\n\t */\n\tcapacity: number;\n\n\t/**\n\t * The number of final IDs currently allocated in the cluster.\n\t */\n\tcount: number;\n}\n\nexport function clustersEqual(a: IdCluster, b: IdCluster): boolean {\n\treturn (\n\t\ta.session.sessionUuid === b.session.sessionUuid &&\n\t\ta.baseFinalId === b.baseFinalId &&\n\t\ta.baseLocalId === b.baseLocalId &&\n\t\ta.capacity === b.capacity &&\n\t\ta.count === b.count\n\t);\n}\n\n/**\n * Returns the final ID that is aligned with the supplied local ID within a cluster.\n * Includes allocated IDs.\n */\nexport function getAlignedFinal(\n\tcluster: IdCluster,\n\tlocalWithin: LocalCompressedId,\n): FinalCompressedId | undefined {\n\tconst clusterOffset =\n\t\tgenCountFromLocalId(localWithin) - genCountFromLocalId(cluster.baseLocalId);\n\tif (clusterOffset < cluster.capacity) {\n\t\treturn ((cluster.baseFinalId as number) + clusterOffset) as FinalCompressedId;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the local ID that is aligned with the supplied final ID within a cluster.\n * Fails if the supplied ID does not fall within the cluster bounds.\n */\nexport function getAlignedLocal(\n\tcluster: IdCluster,\n\tfinalWithin: FinalCompressedId,\n): LocalCompressedId {\n\tassert(\n\t\tfinalWithin >= cluster.baseFinalId && finalWithin <= lastAllocatedFinal(cluster),\n\t\t0x763 /* Supplied ID is not within the cluster. */,\n\t);\n\tconst finalDelta = finalWithin - cluster.baseFinalId;\n\treturn (cluster.baseLocalId - finalDelta) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + capacity) within a cluster\n */\nexport function lastAllocatedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.capacity - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + count) within a cluster\n */\nexport function lastFinalizedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.count - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + capacity) within a cluster\n */\nexport function lastAllocatedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.capacity - 1)) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster\n */\nexport function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.count - 1)) as LocalCompressedId;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=appendOnlySortedMap.perf.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appendOnlySortedMap.perf.spec.d.ts","sourceRoot":"","sources":["../../src/test/appendOnlySortedMap.perf.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,49 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { benchmark, BenchmarkType } from "@fluid-tools/benchmark";
6
+ import { makeRandom } from "@fluid-private/stochastic-test-utils";
7
+ import { AppendOnlySortedMap } from "../appendOnlySortedMap.js";
8
+ import { compareFiniteNumbers } from "../utilities.js";
9
+ function runAppendOnlyMapPerfTests(mapBuilder) {
10
+ const type = BenchmarkType.Measurement;
11
+ let map;
12
+ let rand;
13
+ const keyChoices = [];
14
+ let localChoice = 0;
15
+ const before = () => {
16
+ rand = makeRandom(42);
17
+ map = mapBuilder();
18
+ let curKey = 0;
19
+ for (let i = 0; i < 100000; i++) {
20
+ map.append(curKey, rand.integer(0, Number.MAX_SAFE_INTEGER));
21
+ curKey += rand.integer(1, 10);
22
+ }
23
+ const keys = [...map.keys()];
24
+ for (let i = 0; i < map.size; i++) {
25
+ keyChoices.push(keys[rand.integer(0, map.size - 1)]);
26
+ }
27
+ localChoice = 0;
28
+ };
29
+ benchmark({
30
+ type,
31
+ title: `lookup a key`,
32
+ before,
33
+ benchmarkFn: () => {
34
+ map.get(keyChoices[localChoice++ % keyChoices.length]);
35
+ },
36
+ });
37
+ benchmark({
38
+ type,
39
+ title: `lookup a pair or lower`,
40
+ before,
41
+ benchmarkFn: () => {
42
+ map.getPairOrNextLower(keyChoices[localChoice++ % keyChoices.length]);
43
+ },
44
+ });
45
+ }
46
+ describe("AppendOnlySortedMap Perf", () => {
47
+ runAppendOnlyMapPerfTests(() => new AppendOnlySortedMap(compareFiniteNumbers));
48
+ });
49
+ //# sourceMappingURL=appendOnlySortedMap.perf.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appendOnlySortedMap.perf.spec.js","sourceRoot":"","sources":["../../src/test/appendOnlySortedMap.perf.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAW,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE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C;KACD,CAAC,CAAC;IAEH,SAAS,CAAC;QACT,IAAI;QACJ,KAAK,EAAE,wBAAwB;QAC/B,MAAM;QACN,WAAW,EAAE,GAAG,EAAE;YACjB,GAAG,CAAC,kBAAkB,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACzC,yBAAyB,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { benchmark, BenchmarkType } from \"@fluid-tools/benchmark\";\nimport { IRandom, makeRandom } from \"@fluid-private/stochastic-test-utils\";\nimport { AppendOnlySortedMap } from \"../appendOnlySortedMap.js\";\nimport { compareFiniteNumbers } from \"../utilities.js\";\n\nfunction runAppendOnlyMapPerfTests(mapBuilder: () => AppendOnlySortedMap<number, number>) {\n\tconst type = BenchmarkType.Measurement;\n\tlet map: AppendOnlySortedMap<number, number>;\n\tlet rand: IRandom;\n\tconst keyChoices: number[] = [];\n\tlet localChoice = 0;\n\tconst before = () => {\n\t\trand = makeRandom(42);\n\t\tmap = mapBuilder();\n\t\tlet curKey = 0;\n\t\tfor (let i = 0; i < 100000; i++) {\n\t\t\tmap.append(curKey, rand.integer(0, Number.MAX_SAFE_INTEGER));\n\t\t\tcurKey += rand.integer(1, 10);\n\t\t}\n\t\tconst keys = [...map.keys()];\n\t\tfor (let i = 0; i < map.size; i++) {\n\t\t\tkeyChoices.push(keys[rand.integer(0, map.size - 1)]);\n\t\t}\n\t\tlocalChoice = 0;\n\t};\n\n\tbenchmark({\n\t\ttype,\n\t\ttitle: `lookup a key`,\n\t\tbefore,\n\t\tbenchmarkFn: () => {\n\t\t\tmap.get(keyChoices[localChoice++ % keyChoices.length]);\n\t\t},\n\t});\n\n\tbenchmark({\n\t\ttype,\n\t\ttitle: `lookup a pair or lower`,\n\t\tbefore,\n\t\tbenchmarkFn: () => {\n\t\t\tmap.getPairOrNextLower(keyChoices[localChoice++ % keyChoices.length]);\n\t\t},\n\t});\n}\n\ndescribe(\"AppendOnlySortedMap Perf\", () => {\n\trunAppendOnlyMapPerfTests(() => new AppendOnlySortedMap(compareFiniteNumbers));\n});\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=appendOnlySortedMap.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appendOnlySortedMap.spec.d.ts","sourceRoot":"","sources":["../../src/test/appendOnlySortedMap.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,166 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /* eslint-disable no-bitwise */
6
+ import { strict as assert } from "assert";
7
+ import { AppendOnlySortedMap } from "../appendOnlySortedMap.js";
8
+ import { compareFiniteNumbers } from "../utilities.js";
9
+ import { assertNotUndefined } from "./testCommon.js";
10
+ function runAppendOnlyMapTests(mapBuilder) {
11
+ it("detects out-of-order keys", () => {
12
+ const map = mapBuilder();
13
+ map.append(0, 0);
14
+ const exception = "Inserted key must be > all others in the map.";
15
+ assert.throws(() => map.append(-1, 1), (e) => e.message === exception);
16
+ map.append(1, 2);
17
+ });
18
+ it("can get the min and max keys", () => {
19
+ const map = mapBuilder();
20
+ const elementCount = 10;
21
+ assert.equal(map.maxKey(), undefined);
22
+ for (let i = 0; i < elementCount; i++) {
23
+ map.append(i, i);
24
+ assert.equal(map.maxKey(), i);
25
+ assert.equal(map.minKey(), 0);
26
+ }
27
+ });
28
+ it("can get the first and last pairs", () => {
29
+ const map = mapBuilder();
30
+ const elementCount = 10;
31
+ assert.equal(map.first(), undefined);
32
+ assert.equal(map.last(), undefined);
33
+ for (let i = 0; i < elementCount; i++) {
34
+ map.append(i, i);
35
+ assert.deepEqual(map.last(), [i, i]);
36
+ assert.deepEqual(map.first(), [0, 0]);
37
+ }
38
+ });
39
+ it("can get values", () => {
40
+ const map = mapBuilder();
41
+ const elementCount = 10;
42
+ for (let i = 0; i < elementCount; i++) {
43
+ map.append(i, i);
44
+ }
45
+ assert.equal(map.get(-1), undefined);
46
+ assert.equal(map.get(10), undefined);
47
+ for (let i = 0; i < elementCount; i++) {
48
+ assert.equal(map.get(i), i);
49
+ }
50
+ });
51
+ it("can get pairs by index", () => {
52
+ const map = mapBuilder();
53
+ const elementCount = 10;
54
+ for (let i = 0; i < elementCount; i++) {
55
+ map.append(i * 10, i);
56
+ }
57
+ assert.equal(map.getAtIndex(-1), undefined);
58
+ assert.equal(map.getAtIndex(10), undefined);
59
+ for (let i = 0; i < elementCount; i++) {
60
+ assert.deepEqual(map.getAtIndex(i), [i * 10, i]);
61
+ }
62
+ });
63
+ it("can get an entry or next lower by key", () => {
64
+ [99, 100].forEach((elementCount) => {
65
+ const map = mapBuilder();
66
+ for (let i = 0; i < elementCount; i++) {
67
+ map.append(i * 2, i * 2);
68
+ }
69
+ assert.equal(map.getPairOrNextLower(-1), undefined);
70
+ for (let i = 0; i < map.size; i++) {
71
+ assert.deepEqual(map.getPairOrNextLower(i * 2), [i * 2, i * 2]);
72
+ assert.deepEqual(map.getPairOrNextLower(i * 2 + 1), [i * 2, i * 2]);
73
+ }
74
+ const maxKey = assertNotUndefined(map.maxKey());
75
+ assert.deepEqual(map.getPairOrNextLower(maxKey + 1), [maxKey, maxKey]);
76
+ });
77
+ });
78
+ it("can get an entry or next higher by key", () => {
79
+ [99, 100].forEach((elementCount) => {
80
+ const map = mapBuilder();
81
+ for (let i = 0; i < elementCount; i++) {
82
+ map.append(i * 2, i * 2);
83
+ }
84
+ const minKey = assertNotUndefined(map.minKey());
85
+ assert.deepEqual(map.getPairOrNextHigher(minKey - 1), [minKey, minKey]);
86
+ for (let i = 0; i < map.size - 1; i++) {
87
+ assert.deepEqual(map.getPairOrNextHigher(i * 2), [i * 2, i * 2]);
88
+ assert.deepEqual(map.getPairOrNextHigher(i * 2 + 1), [i * 2 + 2, i * 2 + 2]);
89
+ }
90
+ assert.equal(map.getPairOrNextHigher(map.size * 2 + 1), undefined);
91
+ });
92
+ });
93
+ it("knows how big it is", () => {
94
+ const map = mapBuilder();
95
+ const elementCount = 10;
96
+ for (let i = 0; i < elementCount; i++) {
97
+ assert.equal(map.size, i);
98
+ map.append(i, i);
99
+ }
100
+ assert.equal(map.size, elementCount);
101
+ });
102
+ it("can enumerate its keys and values", () => {
103
+ const map = mapBuilder();
104
+ const elementCount = 10;
105
+ const keys = [];
106
+ const values = [];
107
+ for (let i = 0; i < elementCount; i++) {
108
+ const key = i;
109
+ const value = i * 2;
110
+ map.append(key, value);
111
+ keys.push(key);
112
+ values.push(value);
113
+ }
114
+ assert.deepEqual([...map.keys()], keys);
115
+ assert.deepEqual([...map.values()], values);
116
+ });
117
+ it("can calculate the indexOf a search element", () => {
118
+ const elements = [0, 0, 2, 0, 3, 0];
119
+ const comparator = (search, key, value) => {
120
+ return compareFiniteNumbers(search, key);
121
+ };
122
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, 0, comparator), 0);
123
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, 2, comparator), 2);
124
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, 3, comparator), 4);
125
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, -1, comparator), 0 ^ AppendOnlySortedMap.failureXor);
126
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, 1, comparator), 2 ^ AppendOnlySortedMap.failureXor);
127
+ assert.equal(AppendOnlySortedMap.keyIndexOf(elements, 10, comparator), 6 ^ AppendOnlySortedMap.failureXor);
128
+ });
129
+ describe("can perform range queries", () => {
130
+ const map = mapBuilder();
131
+ const elementCount = 10;
132
+ for (let i = 0; i < elementCount; i++) {
133
+ map.append(i * 2, i * 2);
134
+ }
135
+ const maxKey = assertNotUndefined(map.maxKey());
136
+ it("on empty ranges", () => {
137
+ assert.deepEqual([...map.getRange(1, -1)], []);
138
+ assert.deepEqual([...map.getRange(maxKey + 1, maxKey + 1)], []);
139
+ });
140
+ it("on ranges of size 1", () => {
141
+ assert.deepEqual([...map.getRange(0, 0)], [[0, 0]]);
142
+ assert.deepEqual([...map.getRange(1, 1)], []);
143
+ assert.deepEqual([...map.getRange(-1, -1)], []);
144
+ });
145
+ it("on non-empty ranges", () => {
146
+ assert.deepEqual([...map.getRange(0, 1)], [[0, 0]]);
147
+ assert.deepEqual([...map.getRange(0, 2)], [
148
+ [0, 0],
149
+ [2, 2],
150
+ ]);
151
+ assert.deepEqual([...map.getRange(1, 5)], [
152
+ [2, 2],
153
+ [4, 4],
154
+ ]);
155
+ const allEntries = [...map.entries()];
156
+ assert.deepEqual([...map.getRange(0, maxKey)], allEntries);
157
+ assert.deepEqual([...map.getRange(-maxKey, maxKey)], allEntries);
158
+ assert.deepEqual([...map.getRange(0, 2 * maxKey)], allEntries);
159
+ assert.deepEqual([...map.getRange(-maxKey, 2 * maxKey)], allEntries);
160
+ });
161
+ });
162
+ }
163
+ describe("AppendOnlySortedMap", () => {
164
+ runAppendOnlyMapTests(() => new AppendOnlySortedMap(compareFiniteNumbers));
165
+ });
166
+ //# sourceMappingURL=appendOnlySortedMap.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appendOnlySortedMap.spec.js","sourceRoot":"","sources":["../../src/test/appendOnlySortedMap.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+BAA+B;AAE/B,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,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AC,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;YAC/D,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACpC,qBAAqB,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC","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 { strict as assert } from \"assert\";\nimport { AppendOnlySortedMap } from \"../appendOnlySortedMap.js\";\nimport { compareFiniteNumbers } from \"../utilities.js\";\nimport { assertNotUndefined } from \"./testCommon.js\";\n\nfunction runAppendOnlyMapTests(mapBuilder: () => AppendOnlySortedMap<number, number>) {\n\tit(\"detects out-of-order keys\", () => {\n\t\tconst map = mapBuilder();\n\t\tmap.append(0, 0);\n\t\tconst exception = \"Inserted key must be > all others in the map.\";\n\t\tassert.throws(\n\t\t\t() => map.append(-1, 1),\n\t\t\t(e: Error) => e.message === exception,\n\t\t);\n\t\tmap.append(1, 2);\n\t});\n\n\tit(\"can get the min and max keys\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tassert.equal(map.maxKey(), undefined);\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tmap.append(i, i);\n\t\t\tassert.equal(map.maxKey(), i);\n\t\t\tassert.equal(map.minKey(), 0);\n\t\t}\n\t});\n\n\tit(\"can get the first and last pairs\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tassert.equal(map.first(), undefined);\n\t\tassert.equal(map.last(), undefined);\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tmap.append(i, i);\n\t\t\tassert.deepEqual(map.last(), [i, i]);\n\t\t\tassert.deepEqual(map.first(), [0, 0]);\n\t\t}\n\t});\n\n\tit(\"can get values\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tmap.append(i, i);\n\t\t}\n\t\tassert.equal(map.get(-1), undefined);\n\t\tassert.equal(map.get(10), undefined);\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tassert.equal(map.get(i), i);\n\t\t}\n\t});\n\n\tit(\"can get pairs by index\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tmap.append(i * 10, i);\n\t\t}\n\t\tassert.equal(map.getAtIndex(-1), undefined);\n\t\tassert.equal(map.getAtIndex(10), undefined);\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tassert.deepEqual(map.getAtIndex(i), [i * 10, i]);\n\t\t}\n\t});\n\n\tit(\"can get an entry or next lower by key\", () => {\n\t\t[99, 100].forEach((elementCount) => {\n\t\t\tconst map = mapBuilder();\n\t\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\t\tmap.append(i * 2, i * 2);\n\t\t\t}\n\t\t\tassert.equal(map.getPairOrNextLower(-1), undefined);\n\t\t\tfor (let i = 0; i < map.size; i++) {\n\t\t\t\tassert.deepEqual(map.getPairOrNextLower(i * 2), [i * 2, i * 2]);\n\t\t\t\tassert.deepEqual(map.getPairOrNextLower(i * 2 + 1), [i * 2, i * 2]);\n\t\t\t}\n\t\t\tconst maxKey = assertNotUndefined(map.maxKey());\n\t\t\tassert.deepEqual(map.getPairOrNextLower(maxKey + 1), [maxKey, maxKey]);\n\t\t});\n\t});\n\n\tit(\"can get an entry or next higher by key\", () => {\n\t\t[99, 100].forEach((elementCount) => {\n\t\t\tconst map = mapBuilder();\n\t\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\t\tmap.append(i * 2, i * 2);\n\t\t\t}\n\t\t\tconst minKey = assertNotUndefined(map.minKey());\n\t\t\tassert.deepEqual(map.getPairOrNextHigher(minKey - 1), [minKey, minKey]);\n\t\t\tfor (let i = 0; i < map.size - 1; i++) {\n\t\t\t\tassert.deepEqual(map.getPairOrNextHigher(i * 2), [i * 2, i * 2]);\n\t\t\t\tassert.deepEqual(map.getPairOrNextHigher(i * 2 + 1), [i * 2 + 2, i * 2 + 2]);\n\t\t\t}\n\t\t\tassert.equal(map.getPairOrNextHigher(map.size * 2 + 1), undefined);\n\t\t});\n\t});\n\n\tit(\"knows how big it is\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tassert.equal(map.size, i);\n\t\t\tmap.append(i, i);\n\t\t}\n\t\tassert.equal(map.size, elementCount);\n\t});\n\n\tit(\"can enumerate its keys and values\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tconst keys: number[] = [];\n\t\tconst values: number[] = [];\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tconst key = i;\n\t\t\tconst value = i * 2;\n\t\t\tmap.append(key, value);\n\t\t\tkeys.push(key);\n\t\t\tvalues.push(value);\n\t\t}\n\t\tassert.deepEqual([...map.keys()], keys);\n\t\tassert.deepEqual([...map.values()], values);\n\t});\n\n\tit(\"can calculate the indexOf a search element\", () => {\n\t\tconst elements: number[] = [0, 0, 2, 0, 3, 0];\n\t\tconst comparator = (search: number, key: number, value: number): number => {\n\t\t\treturn compareFiniteNumbers(search, key);\n\t\t};\n\t\tassert.equal(AppendOnlySortedMap.keyIndexOf(elements, 0, comparator), 0);\n\t\tassert.equal(AppendOnlySortedMap.keyIndexOf(elements, 2, comparator), 2);\n\t\tassert.equal(AppendOnlySortedMap.keyIndexOf(elements, 3, comparator), 4);\n\t\tassert.equal(\n\t\t\tAppendOnlySortedMap.keyIndexOf(elements, -1, comparator),\n\t\t\t0 ^ AppendOnlySortedMap.failureXor,\n\t\t);\n\t\tassert.equal(\n\t\t\tAppendOnlySortedMap.keyIndexOf(elements, 1, comparator),\n\t\t\t2 ^ AppendOnlySortedMap.failureXor,\n\t\t);\n\t\tassert.equal(\n\t\t\tAppendOnlySortedMap.keyIndexOf(elements, 10, comparator),\n\t\t\t6 ^ AppendOnlySortedMap.failureXor,\n\t\t);\n\t});\n\n\tdescribe(\"can perform range queries\", () => {\n\t\tconst map = mapBuilder();\n\t\tconst elementCount = 10;\n\t\tfor (let i = 0; i < elementCount; i++) {\n\t\t\tmap.append(i * 2, i * 2);\n\t\t}\n\t\tconst maxKey = assertNotUndefined(map.maxKey());\n\n\t\tit(\"on empty ranges\", () => {\n\t\t\tassert.deepEqual([...map.getRange(1, -1)], []);\n\t\t\tassert.deepEqual([...map.getRange(maxKey + 1, maxKey + 1)], []);\n\t\t});\n\n\t\tit(\"on ranges of size 1\", () => {\n\t\t\tassert.deepEqual([...map.getRange(0, 0)], [[0, 0]]);\n\t\t\tassert.deepEqual([...map.getRange(1, 1)], []);\n\t\t\tassert.deepEqual([...map.getRange(-1, -1)], []);\n\t\t});\n\n\t\tit(\"on non-empty ranges\", () => {\n\t\t\tassert.deepEqual([...map.getRange(0, 1)], [[0, 0]]);\n\t\t\tassert.deepEqual(\n\t\t\t\t[...map.getRange(0, 2)],\n\t\t\t\t[\n\t\t\t\t\t[0, 0],\n\t\t\t\t\t[2, 2],\n\t\t\t\t],\n\t\t\t);\n\t\t\tassert.deepEqual(\n\t\t\t\t[...map.getRange(1, 5)],\n\t\t\t\t[\n\t\t\t\t\t[2, 2],\n\t\t\t\t\t[4, 4],\n\t\t\t\t],\n\t\t\t);\n\t\t\tconst allEntries = [...map.entries()];\n\t\t\tassert.deepEqual([...map.getRange(0, maxKey)], allEntries);\n\t\t\tassert.deepEqual([...map.getRange(-maxKey, maxKey)], allEntries);\n\t\t\tassert.deepEqual([...map.getRange(0, 2 * maxKey)], allEntries);\n\t\t\tassert.deepEqual([...map.getRange(-maxKey, 2 * maxKey)], allEntries);\n\t\t});\n\t});\n}\n\ndescribe(\"AppendOnlySortedMap\", () => {\n\trunAppendOnlyMapTests(() => new AppendOnlySortedMap(compareFiniteNumbers));\n});\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=idCompressor.perf.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.perf.spec.d.ts","sourceRoot":"","sources":["../../src/test/idCompressor.perf.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}