@fluidframework/tree 2.13.0 → 2.20.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 (303) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/api-report/tree.alpha.api.md +22 -12
  3. package/api-report/tree.beta.api.md +9 -5
  4. package/api-report/tree.legacy.alpha.api.md +9 -5
  5. package/api-report/tree.legacy.public.api.md +9 -5
  6. package/api-report/tree.public.api.md +9 -5
  7. package/assertTagging.config.mjs +14 -0
  8. package/dist/alpha.d.ts +3 -0
  9. package/dist/core/index.d.ts +2 -2
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js +6 -4
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/rebase/index.d.ts +2 -2
  14. package/dist/core/rebase/index.d.ts.map +1 -1
  15. package/dist/core/rebase/index.js +5 -1
  16. package/dist/core/rebase/index.js.map +1 -1
  17. package/dist/core/rebase/types.d.ts +5 -4
  18. package/dist/core/rebase/types.d.ts.map +1 -1
  19. package/dist/core/rebase/types.js +29 -1
  20. package/dist/core/rebase/types.js.map +1 -1
  21. package/dist/core/rebase/utils.d.ts +10 -0
  22. package/dist/core/rebase/utils.d.ts.map +1 -1
  23. package/dist/core/rebase/utils.js +22 -1
  24. package/dist/core/rebase/utils.js.map +1 -1
  25. package/dist/core/tree/delta.d.ts +21 -26
  26. package/dist/core/tree/delta.d.ts.map +1 -1
  27. package/dist/core/tree/delta.js.map +1 -1
  28. package/dist/core/tree/deltaUtil.d.ts +1 -3
  29. package/dist/core/tree/deltaUtil.d.ts.map +1 -1
  30. package/dist/core/tree/deltaUtil.js +2 -14
  31. package/dist/core/tree/deltaUtil.js.map +1 -1
  32. package/dist/core/tree/index.d.ts +1 -1
  33. package/dist/core/tree/index.d.ts.map +1 -1
  34. package/dist/core/tree/index.js +1 -3
  35. package/dist/core/tree/index.js.map +1 -1
  36. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  37. package/dist/core/tree/visitDelta.js +82 -80
  38. package/dist/core/tree/visitDelta.js.map +1 -1
  39. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  40. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  41. package/dist/feature-libraries/deltaUtils.d.ts.map +1 -1
  42. package/dist/feature-libraries/deltaUtils.js +13 -0
  43. package/dist/feature-libraries/deltaUtils.js.map +1 -1
  44. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  45. package/dist/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  46. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  47. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  48. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  49. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +2 -9
  50. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  51. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +19 -2
  52. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  53. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  54. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  55. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  56. package/dist/feature-libraries/modular-schema/index.d.ts +2 -2
  57. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  58. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  59. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  60. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  61. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +8 -8
  62. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  63. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +4 -4
  64. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  65. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +105 -199
  66. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  67. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +11 -20
  68. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  69. package/dist/feature-libraries/modular-schema/modularChangeTypes.js +20 -0
  70. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  71. package/dist/feature-libraries/optional-field/optionalField.d.ts +3 -3
  72. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  73. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  74. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  75. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  76. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  77. package/dist/feature-libraries/sequence-field/rebase.js +4 -4
  78. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  79. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  80. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  81. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  82. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  83. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  84. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  85. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  86. package/dist/feature-libraries/sequence-field/utils.js +36 -4
  87. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  88. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  89. package/dist/feature-libraries/treeCursorUtils.js +4 -1
  90. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  91. package/dist/index.d.ts +26 -2
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +4 -2
  94. package/dist/index.js.map +1 -1
  95. package/dist/package.json +2 -1
  96. package/dist/packageVersion.d.ts +1 -1
  97. package/dist/packageVersion.js +1 -1
  98. package/dist/packageVersion.js.map +1 -1
  99. package/dist/shared-tree/index.d.ts +1 -1
  100. package/dist/shared-tree/index.d.ts.map +1 -1
  101. package/dist/shared-tree/index.js +4 -2
  102. package/dist/shared-tree/index.js.map +1 -1
  103. package/dist/shared-tree/sharedTree.d.ts +38 -18
  104. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  105. package/dist/shared-tree/sharedTree.js +38 -34
  106. package/dist/shared-tree/sharedTree.js.map +1 -1
  107. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  108. package/dist/shared-tree/treeCheckout.js +12 -8
  109. package/dist/shared-tree/treeCheckout.js.map +1 -1
  110. package/dist/simple-tree/api/treeNodeApi.js +1 -1
  111. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  112. package/dist/simple-tree/arrayNode.js +1 -1
  113. package/dist/simple-tree/arrayNode.js.map +1 -1
  114. package/dist/simple-tree/toMapTree.js +1 -1
  115. package/dist/simple-tree/toMapTree.js.map +1 -1
  116. package/dist/util/bTreeUtils.d.ts +10 -0
  117. package/dist/util/bTreeUtils.d.ts.map +1 -0
  118. package/dist/util/bTreeUtils.js +52 -0
  119. package/dist/util/bTreeUtils.js.map +1 -0
  120. package/dist/util/idAllocator.d.ts +0 -2
  121. package/dist/util/idAllocator.d.ts.map +1 -1
  122. package/dist/util/idAllocator.js +0 -2
  123. package/dist/util/idAllocator.js.map +1 -1
  124. package/dist/util/index.d.ts +2 -1
  125. package/dist/util/index.d.ts.map +1 -1
  126. package/dist/util/index.js +5 -1
  127. package/dist/util/index.js.map +1 -1
  128. package/dist/util/rangeMap.d.ts +52 -30
  129. package/dist/util/rangeMap.d.ts.map +1 -1
  130. package/dist/util/rangeMap.js +161 -117
  131. package/dist/util/rangeMap.js.map +1 -1
  132. package/dist/util/utils.d.ts +4 -1
  133. package/dist/util/utils.d.ts.map +1 -1
  134. package/dist/util/utils.js +7 -1
  135. package/dist/util/utils.js.map +1 -1
  136. package/lib/alpha.d.ts +3 -0
  137. package/lib/core/index.d.ts +2 -2
  138. package/lib/core/index.d.ts.map +1 -1
  139. package/lib/core/index.js +2 -2
  140. package/lib/core/index.js.map +1 -1
  141. package/lib/core/rebase/index.d.ts +2 -2
  142. package/lib/core/rebase/index.d.ts.map +1 -1
  143. package/lib/core/rebase/index.js +2 -2
  144. package/lib/core/rebase/index.js.map +1 -1
  145. package/lib/core/rebase/types.d.ts +5 -4
  146. package/lib/core/rebase/types.d.ts.map +1 -1
  147. package/lib/core/rebase/types.js +26 -1
  148. package/lib/core/rebase/types.js.map +1 -1
  149. package/lib/core/rebase/utils.d.ts +10 -0
  150. package/lib/core/rebase/utils.d.ts.map +1 -1
  151. package/lib/core/rebase/utils.js +20 -0
  152. package/lib/core/rebase/utils.js.map +1 -1
  153. package/lib/core/tree/delta.d.ts +21 -26
  154. package/lib/core/tree/delta.d.ts.map +1 -1
  155. package/lib/core/tree/delta.js.map +1 -1
  156. package/lib/core/tree/deltaUtil.d.ts +1 -3
  157. package/lib/core/tree/deltaUtil.d.ts.map +1 -1
  158. package/lib/core/tree/deltaUtil.js +1 -12
  159. package/lib/core/tree/deltaUtil.js.map +1 -1
  160. package/lib/core/tree/index.d.ts +1 -1
  161. package/lib/core/tree/index.d.ts.map +1 -1
  162. package/lib/core/tree/index.js +1 -1
  163. package/lib/core/tree/index.js.map +1 -1
  164. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  165. package/lib/core/tree/visitDelta.js +82 -80
  166. package/lib/core/tree/visitDelta.js.map +1 -1
  167. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  168. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  169. package/lib/feature-libraries/deltaUtils.d.ts.map +1 -1
  170. package/lib/feature-libraries/deltaUtils.js +13 -0
  171. package/lib/feature-libraries/deltaUtils.js.map +1 -1
  172. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  173. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  174. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  175. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  176. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  177. package/lib/feature-libraries/modular-schema/crossFieldQueries.js +2 -9
  178. package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  179. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +19 -2
  180. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  181. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  182. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  183. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  184. package/lib/feature-libraries/modular-schema/index.d.ts +2 -2
  185. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  186. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  187. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  188. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  189. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  190. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  191. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +4 -4
  192. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  193. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +74 -166
  194. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  195. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +11 -20
  196. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  197. package/lib/feature-libraries/modular-schema/modularChangeTypes.js +18 -1
  198. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  199. package/lib/feature-libraries/optional-field/optionalField.d.ts +3 -3
  200. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  201. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  202. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  203. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  204. package/lib/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  205. package/lib/feature-libraries/sequence-field/rebase.js +4 -4
  206. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  207. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  208. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  209. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  210. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  211. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  212. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  213. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  214. package/lib/feature-libraries/sequence-field/utils.js +36 -4
  215. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  216. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  217. package/lib/feature-libraries/treeCursorUtils.js +4 -1
  218. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  219. package/lib/index.d.ts +26 -2
  220. package/lib/index.d.ts.map +1 -1
  221. package/lib/index.js +1 -1
  222. package/lib/index.js.map +1 -1
  223. package/lib/packageVersion.d.ts +1 -1
  224. package/lib/packageVersion.js +1 -1
  225. package/lib/packageVersion.js.map +1 -1
  226. package/lib/shared-tree/index.d.ts +1 -1
  227. package/lib/shared-tree/index.d.ts.map +1 -1
  228. package/lib/shared-tree/index.js +1 -1
  229. package/lib/shared-tree/index.js.map +1 -1
  230. package/lib/shared-tree/sharedTree.d.ts +38 -18
  231. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  232. package/lib/shared-tree/sharedTree.js +37 -33
  233. package/lib/shared-tree/sharedTree.js.map +1 -1
  234. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  235. package/lib/shared-tree/treeCheckout.js +13 -9
  236. package/lib/shared-tree/treeCheckout.js.map +1 -1
  237. package/lib/simple-tree/api/treeNodeApi.js +1 -1
  238. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  239. package/lib/simple-tree/arrayNode.js +1 -1
  240. package/lib/simple-tree/arrayNode.js.map +1 -1
  241. package/lib/simple-tree/toMapTree.js +1 -1
  242. package/lib/simple-tree/toMapTree.js.map +1 -1
  243. package/lib/util/bTreeUtils.d.ts +10 -0
  244. package/lib/util/bTreeUtils.d.ts.map +1 -0
  245. package/lib/util/bTreeUtils.js +47 -0
  246. package/lib/util/bTreeUtils.js.map +1 -0
  247. package/lib/util/idAllocator.d.ts +0 -2
  248. package/lib/util/idAllocator.d.ts.map +1 -1
  249. package/lib/util/idAllocator.js +0 -2
  250. package/lib/util/idAllocator.js.map +1 -1
  251. package/lib/util/index.d.ts +2 -1
  252. package/lib/util/index.d.ts.map +1 -1
  253. package/lib/util/index.js +2 -1
  254. package/lib/util/index.js.map +1 -1
  255. package/lib/util/rangeMap.d.ts +52 -30
  256. package/lib/util/rangeMap.d.ts.map +1 -1
  257. package/lib/util/rangeMap.js +160 -117
  258. package/lib/util/rangeMap.js.map +1 -1
  259. package/lib/util/utils.d.ts +4 -1
  260. package/lib/util/utils.d.ts.map +1 -1
  261. package/lib/util/utils.js +7 -1
  262. package/lib/util/utils.js.map +1 -1
  263. package/package.json +23 -23
  264. package/src/core/index.ts +5 -2
  265. package/src/core/rebase/index.ts +5 -0
  266. package/src/core/rebase/types.ts +33 -5
  267. package/src/core/rebase/utils.ts +27 -0
  268. package/src/core/tree/delta.ts +21 -26
  269. package/src/core/tree/deltaUtil.ts +1 -16
  270. package/src/core/tree/index.ts +0 -2
  271. package/src/core/tree/visitDelta.ts +108 -97
  272. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +2 -2
  273. package/src/feature-libraries/deltaUtils.ts +13 -0
  274. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -6
  275. package/src/feature-libraries/modular-schema/crossFieldQueries.ts +12 -13
  276. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +21 -1
  277. package/src/feature-libraries/modular-schema/genericFieldKind.ts +2 -2
  278. package/src/feature-libraries/modular-schema/index.ts +2 -0
  279. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +12 -11
  280. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +138 -225
  281. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +40 -27
  282. package/src/feature-libraries/optional-field/optionalField.ts +3 -3
  283. package/src/feature-libraries/sequence-field/moveEffectTable.ts +1 -1
  284. package/src/feature-libraries/sequence-field/rebase.ts +9 -3
  285. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +1 -1
  286. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +1 -1
  287. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +3 -4
  288. package/src/feature-libraries/sequence-field/utils.ts +36 -4
  289. package/src/feature-libraries/treeCursorUtils.ts +6 -1
  290. package/src/index.ts +34 -6
  291. package/src/packageVersion.ts +1 -1
  292. package/src/shared-tree/index.ts +4 -1
  293. package/src/shared-tree/sharedTree.ts +60 -40
  294. package/src/shared-tree/treeCheckout.ts +19 -12
  295. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  296. package/src/simple-tree/arrayNode.ts +1 -1
  297. package/src/simple-tree/toMapTree.ts +1 -1
  298. package/src/util/bTreeUtils.ts +60 -0
  299. package/src/util/idAllocator.ts +0 -2
  300. package/src/util/index.ts +3 -0
  301. package/src/util/rangeMap.ts +208 -143
  302. package/src/util/utils.ts +10 -3
  303. package/lib/package.json +0 -3
@@ -0,0 +1,47 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { BTree } from "@tylerbu/sorted-btree-es6";
6
+ import { brand } from "./brand.js";
7
+ export function newTupleBTree(entries) {
8
+ return brand(new BTree(entries, compareTuples));
9
+ }
10
+ // This assumes that the arrays are the same length.
11
+ function compareTuples(arrayA, arrayB) {
12
+ for (let i = 0; i < arrayA.length; i++) {
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const a = arrayA[i];
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ const b = arrayB[i];
17
+ // Less-than and greater-than always return false if either value is undefined,
18
+ // so we handle undefined separately, treating it as less than all other values.
19
+ if (a === undefined && b !== undefined) {
20
+ return -1;
21
+ }
22
+ else if (b === undefined && a !== undefined) {
23
+ return 1;
24
+ }
25
+ else if (a < b) {
26
+ return -1;
27
+ }
28
+ else if (a > b) {
29
+ return 1;
30
+ }
31
+ }
32
+ return 0;
33
+ }
34
+ export function mergeTupleBTrees(tree1, tree2, preferLeft = true) {
35
+ if (tree1 === undefined) {
36
+ return tree2 !== undefined ? brand(tree2.clone()) : newTupleBTree();
37
+ }
38
+ const result = brand(tree1.clone());
39
+ if (tree2 === undefined) {
40
+ return result;
41
+ }
42
+ for (const [key, value] of tree2.entries()) {
43
+ result.set(key, value, !preferLeft);
44
+ }
45
+ return result;
46
+ }
47
+ //# sourceMappingURL=bTreeUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bTreeUtils.js","sourceRoot":"","sources":["../../src/util/bTreeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,KAAK,EAAc,MAAM,YAAY,CAAC;AAI/C,MAAM,UAAU,aAAa,CAC5B,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O,MAAM,CAAC;IACf,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,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 { brand, type Brand } from \"./brand.js\";\n\nexport type TupleBTree<K, V> = Brand<BTree<K, V>, \"TupleBTree\">;\n\nexport function newTupleBTree<K extends readonly unknown[], V>(\n\tentries?: [K, V][],\n): TupleBTree<K, V> {\n\treturn brand(new BTree<K, V>(entries, compareTuples));\n}\n\n// This assumes that the arrays are the same length.\nfunction compareTuples(arrayA: readonly unknown[], arrayB: readonly unknown[]): number {\n\tfor (let i = 0; i < arrayA.length; i++) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst a = arrayA[i] as any;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst b = arrayB[i] as any;\n\n\t\t// Less-than and greater-than always return false if either value is undefined,\n\t\t// so we handle undefined separately, treating it as less than all other values.\n\t\tif (a === undefined && b !== undefined) {\n\t\t\treturn -1;\n\t\t} else if (b === undefined && a !== undefined) {\n\t\t\treturn 1;\n\t\t} else if (a < b) {\n\t\t\treturn -1;\n\t\t} else if (a > b) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\nexport function mergeTupleBTrees<K extends readonly unknown[], V>(\n\ttree1: TupleBTree<K, V> | undefined,\n\ttree2: TupleBTree<K, V> | undefined,\n\tpreferLeft = true,\n): TupleBTree<K, V> {\n\tif (tree1 === undefined) {\n\t\treturn tree2 !== undefined ? brand(tree2.clone()) : newTupleBTree<K, V>();\n\t}\n\n\tconst result: TupleBTree<K, V> = brand(tree1.clone());\n\tif (tree2 === undefined) {\n\t\treturn result;\n\t}\n\n\tfor (const [key, value] of tree2.entries()) {\n\t\tresult.set(key, value, !preferLeft);\n\t}\n\n\treturn result;\n}\n"]}
@@ -19,8 +19,6 @@ export interface IdAllocator<TId = number> {
19
19
  export interface IdAllocationState {
20
20
  maxId: number;
21
21
  }
22
- /**
23
- */
24
22
  export declare function idAllocatorFromMaxId(maxId?: number | undefined): IdAllocator;
25
23
  export declare function idAllocatorFromState(state: IdAllocationState): IdAllocator;
26
24
  export declare const fakeIdAllocator: IdAllocator;
@@ -1 +1 @@
1
- {"version":3,"file":"idAllocator.d.ts","sourceRoot":"","sources":["../../src/util/idAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,GAAG,GAAG,MAAM;IACxC;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;IAClC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IACjC,KAAK,EAAE,MAAM,CAAC;CACd;AAED;GACG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,GAAE,MAAM,GAAG,SAAqB,GAAG,WAAW,CAEvF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAW1E;AAED,eAAO,MAAM,eAAe,EAAE,WAG7B,CAAC"}
1
+ {"version":3,"file":"idAllocator.d.ts","sourceRoot":"","sources":["../../src/util/idAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,GAAG,GAAG,MAAM;IACxC;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;IAClC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IACjC,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,oBAAoB,CAAC,KAAK,GAAE,MAAM,GAAG,SAAqB,GAAG,WAAW,CAEvF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAW1E;AAED,eAAO,MAAM,eAAe,EAAE,WAG7B,CAAC"}
@@ -4,8 +4,6 @@
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
6
  import { fail } from "./utils.js";
7
- /**
8
- */
9
7
  export function idAllocatorFromMaxId(maxId = undefined) {
10
8
  return idAllocatorFromState({ maxId: maxId ?? -1 });
11
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"idAllocator.js","sourceRoot":"","sources":["../../src/util/idAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAqBlC;GACG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAA4B,SAAS;IACzE,OAAO,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAwB;IAC5D,OAAO;QACN,QAAQ,EAAE,CAAC,CAAU,EAAU,EAAE;YAChC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;YACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAC7D,MAAM,EAAE,GAAW,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;YACnC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC;YACrB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK;KAC3B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAgB;IAC3C,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC;IAC/C,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;CACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { fail } from \"./utils.js\";\n\n/**\n * Used for allocating IDs unique to a particular instance of the allocator.\n */\nexport interface IdAllocator<TId = number> {\n\t/**\n\t * Allocates a block of `count` consecutive IDs and returns the first ID in the block.\n\t * For convenience can be called with no parameters to allocate a single ID.\n\t */\n\tallocate: (count?: number) => TId;\n\t/**\n\t * @returns The maximum ID that was generated by this allocator.\n\t */\n\tgetMaxId: () => TId;\n}\n\nexport interface IdAllocationState {\n\tmaxId: number;\n}\n\n/**\n */\nexport function idAllocatorFromMaxId(maxId: number | undefined = undefined): IdAllocator {\n\treturn idAllocatorFromState({ maxId: maxId ?? -1 });\n}\n\nexport function idAllocatorFromState(state: IdAllocationState): IdAllocator {\n\treturn {\n\t\tallocate: (c?: number): number => {\n\t\t\tconst count = c ?? 1;\n\t\t\tassert(count > 0, 0x5cf /* Must allocate at least one ID */);\n\t\t\tconst id: number = state.maxId + 1;\n\t\t\tstate.maxId += count;\n\t\t\treturn id;\n\t\t},\n\t\tgetMaxId: () => state.maxId,\n\t};\n}\n\nexport const fakeIdAllocator: IdAllocator = {\n\tallocate: () => fail(\"Should not allocate IDs\"),\n\tgetMaxId: () => 0,\n};\n"]}
1
+ {"version":3,"file":"idAllocator.js","sourceRoot":"","sources":["../../src/util/idAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAqBlC,MAAM,UAAU,oBAAoB,CAAC,QAA4B,SAAS;IACzE,OAAO,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAwB;IAC5D,OAAO;QACN,QAAQ,EAAE,CAAC,CAAU,EAAU,EAAE;YAChC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;YACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAC7D,MAAM,EAAE,GAAW,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;YACnC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC;YACrB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK;KAC3B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAgB;IAC3C,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC;IAC/C,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;CACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { fail } from \"./utils.js\";\n\n/**\n * Used for allocating IDs unique to a particular instance of the allocator.\n */\nexport interface IdAllocator<TId = number> {\n\t/**\n\t * Allocates a block of `count` consecutive IDs and returns the first ID in the block.\n\t * For convenience can be called with no parameters to allocate a single ID.\n\t */\n\tallocate: (count?: number) => TId;\n\t/**\n\t * @returns The maximum ID that was generated by this allocator.\n\t */\n\tgetMaxId: () => TId;\n}\n\nexport interface IdAllocationState {\n\tmaxId: number;\n}\n\nexport function idAllocatorFromMaxId(maxId: number | undefined = undefined): IdAllocator {\n\treturn idAllocatorFromState({ maxId: maxId ?? -1 });\n}\n\nexport function idAllocatorFromState(state: IdAllocationState): IdAllocator {\n\treturn {\n\t\tallocate: (c?: number): number => {\n\t\t\tconst count = c ?? 1;\n\t\t\tassert(count > 0, 0x5cf /* Must allocate at least one ID */);\n\t\t\tconst id: number = state.maxId + 1;\n\t\t\tstate.maxId += count;\n\t\t\treturn id;\n\t\t},\n\t\tgetMaxId: () => state.maxId,\n\t};\n}\n\nexport const fakeIdAllocator: IdAllocator = {\n\tallocate: () => fail(\"Should not allocate IDs\"),\n\tgetMaxId: () => 0,\n};\n"]}
@@ -15,7 +15,8 @@ export { ReferenceCountedBase, type ReferenceCounted } from "./referenceCounting
15
15
  export type { _RecursiveTrick, RestrictiveReadonlyRecord, RestrictiveStringRecord, _InlineTrick, FlattenKeys, IsUnion, UnionToIntersection, UnionToTuple, PopUnion, } from "./typeUtils.js";
16
16
  export { unsafeArrayToTuple } from "./typeUtils.js";
17
17
  export { type BrandedKey, type BrandedKeyContent, type BrandedMapSubset, getOrCreateSlotContent, brandedSlot, } from "./brandedMap.js";
18
- export { RangeMap, type RangeQueryResult, } from "./rangeMap.js";
18
+ export { RangeMap, type RangeQueryResult, newIntegerRangeMap, } from "./rangeMap.js";
19
19
  export { type IdAllocator, idAllocatorFromMaxId, idAllocatorFromState, type IdAllocationState, fakeIdAllocator, } from "./idAllocator.js";
20
20
  export { Breakable, type WithBreakable, breakingMethod, throwIfBroken, breakingClass, } from "./breakable.js";
21
+ export { type TupleBTree, newTupleBTree, mergeTupleBTrees } from "./bTreeUtils.js";
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EACL,KAAK,KAAK,EACV,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,KAAK,iB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O,EACP,SAAS,EACT,wBAAwB,EACxB,qBAAqB,IAAI,YAAY,GACrC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAErF,YAAY,EACX,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,QAAQ,GACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EACN,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,QAAQ,EACR,KAAK,gBAAgB,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACN,KAAK,WAAW,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EACL,KAAK,KAAK,EACV,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,MAAM,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,SAAS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AAY,EACX,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,QAAQ,GACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EACN,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,QAAQ,EACR,KAAK,gBAAgB,EACrB,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACN,KAAK,WAAW,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
package/lib/util/index.js CHANGED
@@ -13,7 +13,8 @@ export { asMutable, clone, compareSets, fail, getOrAddEmptyToMap, getOrCreate, i
13
13
  export { ReferenceCountedBase } from "./referenceCounting.js";
14
14
  export { unsafeArrayToTuple } from "./typeUtils.js";
15
15
  export { getOrCreateSlotContent, brandedSlot, } from "./brandedMap.js";
16
- export { RangeMap, } from "./rangeMap.js";
16
+ export { RangeMap, newIntegerRangeMap, } from "./rangeMap.js";
17
17
  export { idAllocatorFromMaxId, idAllocatorFromState, fakeIdAllocator, } from "./idAllocator.js";
18
18
  export { Breakable, breakingMethod, throwIfBroken, breakingClass, } from "./breakable.js";
19
+ export { newTupleBTree, mergeTupleBTrees } from "./bTreeUtils.js";
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.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,EACN,QAAQ,GAER,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEN,oBAAoB,EACpB,oBAAoB,EAEpB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EAET,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tbrand,\n\ttype Brand,\n\tBrandedType,\n\ttype NameFromBranded,\n\ttype ValueFromBranded,\n} from \"./brand.js\";\nexport { brandedNumberType, brandedStringType } from \"./typeboxBrand.js\";\nexport {\n\tbrandOpaque,\n\textractFromOpaque,\n\ttype ExtractFromOpaque,\n\ttype Opaque,\n} from \"./opaque.js\";\nexport {\n\tdeleteFromNestedMap,\n\tgetOrAddInMap,\n\tgetOrAddInMapLazy,\n\tgetOrAddInNestedMap,\n\tgetOrDefaultInNestedMap,\n\tforEachInNestedMap,\n\ttype NestedMap,\n\ttype ReadonlyNestedMap,\n\tSizedNestedMap,\n\tpopulateNestedMap,\n\tsetInNestedMap,\n\ttryAddToNestedMap,\n\ttryGetFromNestedMap,\n\tmapNestedMap,\n\tnestedMapToFlatList,\n\tnestedMapFromFlatList,\n} from \"./nestedMap.js\";\nexport { addToNestedSet, type NestedSet, nestedSetContains } from \"./nestedSet.js\";\nexport { type OffsetList, OffsetListFactory } from \"./offsetList.js\";\nexport type {\n\tareSafelyAssignable,\n\tContravariant,\n\tCovariant,\n\teitherIsAny,\n\tEnforceTypeCheckTests,\n\tInvariant,\n\tisAny,\n\tisAssignableTo,\n\tisStrictSubset,\n\tMakeNominal,\n\trequireFalse,\n\trequireTrue,\n\trequireAssignableTo,\n\tareOnlyKeys,\n} from \"./typeCheck.js\";\nexport { StackyIterator } from \"./stackyIterator.js\";\nexport {\n\tasMutable,\n\tclone,\n\tcompareSets,\n\tfail,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n\tisJsonObject,\n\tisReadonlyArray,\n\ttype JsonCompatible,\n\ttype JsonCompatibleObject,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n\tJsonCompatibleReadOnlySchema,\n\tmakeArray,\n\tmapIterable,\n\tfilterIterable,\n\ttype Mutable,\n\ttype Populated,\n\ttype RecursiveReadonly,\n\tassertValidIndex,\n\tassertValidRange,\n\tassertNonNegativeSafeInteger,\n\tobjectToMap,\n\tinvertMap,\n\toneFromSet,\n\ttype Named,\n\tcompareNamed,\n\tdisposeSymbol,\n\ttype IDisposable,\n\tcapitalize,\n\tassertValidRangeIndices,\n\ttransformObjectMap,\n\tcompareStrings,\n\tfind,\n\tcount,\n\tgetLast,\n\thasSome,\n\thasSingle,\n\tdefineLazyCachedProperty,\n\tcopyPropertyIfDefined as copyProperty,\n} from \"./utils.js\";\nexport { ReferenceCountedBase, type ReferenceCounted } from \"./referenceCounting.js\";\n\nexport type {\n\t_RecursiveTrick,\n\tRestrictiveReadonlyRecord,\n\tRestrictiveStringRecord,\n\t_InlineTrick,\n\tFlattenKeys,\n\tIsUnion,\n\tUnionToIntersection,\n\tUnionToTuple,\n\tPopUnion,\n} from \"./typeUtils.js\";\n\nexport { unsafeArrayToTuple } from \"./typeUtils.js\";\n\nexport {\n\ttype BrandedKey,\n\ttype BrandedKeyContent,\n\ttype BrandedMapSubset,\n\tgetOrCreateSlotContent,\n\tbrandedSlot,\n} from \"./brandedMap.js\";\n\nexport {\n\tRangeMap,\n\ttype RangeQueryResult,\n} from \"./rangeMap.js\";\n\nexport {\n\ttype IdAllocator,\n\tidAllocatorFromMaxId,\n\tidAllocatorFromState,\n\ttype IdAllocationState,\n\tfakeIdAllocator,\n} from \"./idAllocator.js\";\n\nexport {\n\tBreakable,\n\ttype WithBreakable,\n\tbreakingMethod,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"./breakable.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names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AAQ,EAER,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEN,oBAAoB,EACpB,oBAAoB,EAEpB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EAET,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAmB,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tbrand,\n\ttype Brand,\n\tBrandedType,\n\ttype NameFromBranded,\n\ttype ValueFromBranded,\n} from \"./brand.js\";\nexport { brandedNumberType, brandedStringType } from \"./typeboxBrand.js\";\nexport {\n\tbrandOpaque,\n\textractFromOpaque,\n\ttype ExtractFromOpaque,\n\ttype Opaque,\n} from \"./opaque.js\";\nexport {\n\tdeleteFromNestedMap,\n\tgetOrAddInMap,\n\tgetOrAddInMapLazy,\n\tgetOrAddInNestedMap,\n\tgetOrDefaultInNestedMap,\n\tforEachInNestedMap,\n\ttype NestedMap,\n\ttype ReadonlyNestedMap,\n\tSizedNestedMap,\n\tpopulateNestedMap,\n\tsetInNestedMap,\n\ttryAddToNestedMap,\n\ttryGetFromNestedMap,\n\tmapNestedMap,\n\tnestedMapToFlatList,\n\tnestedMapFromFlatList,\n} from \"./nestedMap.js\";\nexport { addToNestedSet, type NestedSet, nestedSetContains } from \"./nestedSet.js\";\nexport { type OffsetList, OffsetListFactory } from \"./offsetList.js\";\nexport type {\n\tareSafelyAssignable,\n\tContravariant,\n\tCovariant,\n\teitherIsAny,\n\tEnforceTypeCheckTests,\n\tInvariant,\n\tisAny,\n\tisAssignableTo,\n\tisStrictSubset,\n\tMakeNominal,\n\trequireFalse,\n\trequireTrue,\n\trequireAssignableTo,\n\tareOnlyKeys,\n} from \"./typeCheck.js\";\nexport { StackyIterator } from \"./stackyIterator.js\";\nexport {\n\tasMutable,\n\tclone,\n\tcompareSets,\n\tfail,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n\tisJsonObject,\n\tisReadonlyArray,\n\ttype JsonCompatible,\n\ttype JsonCompatibleObject,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n\tJsonCompatibleReadOnlySchema,\n\tmakeArray,\n\tmapIterable,\n\tfilterIterable,\n\ttype Mutable,\n\ttype Populated,\n\ttype RecursiveReadonly,\n\tassertValidIndex,\n\tassertValidRange,\n\tassertNonNegativeSafeInteger,\n\tobjectToMap,\n\tinvertMap,\n\toneFromSet,\n\ttype Named,\n\tcompareNamed,\n\tdisposeSymbol,\n\ttype IDisposable,\n\tcapitalize,\n\tassertValidRangeIndices,\n\ttransformObjectMap,\n\tcompareStrings,\n\tfind,\n\tcount,\n\tgetLast,\n\thasSome,\n\thasSingle,\n\tdefineLazyCachedProperty,\n\tcopyPropertyIfDefined as copyProperty,\n} from \"./utils.js\";\nexport { ReferenceCountedBase, type ReferenceCounted } from \"./referenceCounting.js\";\n\nexport type {\n\t_RecursiveTrick,\n\tRestrictiveReadonlyRecord,\n\tRestrictiveStringRecord,\n\t_InlineTrick,\n\tFlattenKeys,\n\tIsUnion,\n\tUnionToIntersection,\n\tUnionToTuple,\n\tPopUnion,\n} from \"./typeUtils.js\";\n\nexport { unsafeArrayToTuple } from \"./typeUtils.js\";\n\nexport {\n\ttype BrandedKey,\n\ttype BrandedKeyContent,\n\ttype BrandedMapSubset,\n\tgetOrCreateSlotContent,\n\tbrandedSlot,\n} from \"./brandedMap.js\";\n\nexport {\n\tRangeMap,\n\ttype RangeQueryResult,\n\tnewIntegerRangeMap,\n} from \"./rangeMap.js\";\n\nexport {\n\ttype IdAllocator,\n\tidAllocatorFromMaxId,\n\tidAllocatorFromState,\n\ttype IdAllocationState,\n\tfakeIdAllocator,\n} from \"./idAllocator.js\";\n\nexport {\n\tBreakable,\n\ttype WithBreakable,\n\tbreakingMethod,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"./breakable.js\";\n\nexport { type TupleBTree, newTupleBTree, mergeTupleBTrees } from \"./bTreeUtils.js\";\n"]}
@@ -3,26 +3,49 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  /**
6
- * RangeMap represents a mapping from integers to values of type T or undefined.
6
+ * RangeMap represents a mapping from keys of type K to values of type V or undefined.
7
+ * The set of all possible keys is assumed to be fully ordered,
8
+ * and for each key there should be a single next higher key.
7
9
  * The values for a range of consecutive keys can be changed or queried in a single operation.
10
+ * The structure of the keys is described by the `offsetKey` and `subtractKeys` functions provided in the constructor.
8
11
  */
9
- export declare class RangeMap<T> {
10
- private readonly entries;
11
- constructor(initialEntries?: RangeEntry<T>[]);
12
+ export declare class RangeMap<K, V> {
13
+ private readonly offsetKey;
14
+ private readonly subtractKeys;
15
+ private tree;
12
16
  /**
13
- * Retrieves all entries from the rangeMap.
14
- * @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
17
+ * @param offsetKey - Function which returns a new key which is `offset` keys after `key`.
18
+ * When `offset` is negative, the returned key should come before `key`.
19
+ *
20
+ * @param subtractKeys - Function which returns the difference between `b` and `a`.
21
+ * Offsetting `b` by this difference should return `a`.
22
+ * The difference can be infinite if `a` cannot be reached from `b` by offsetting,
23
+ * but the difference should still be positive if `a` is larger than `b` and negative if smaller.
24
+ */
25
+ constructor(offsetKey: (key: K, offset: number) => K, subtractKeys: (a: K, b: K) => number);
26
+ /**
27
+ * Retrieves all entries from the RangeMap.
15
28
  */
16
- getAllEntries(): readonly RangeQueryResult<T>[];
29
+ entries(): RangeQueryEntry<K, V>[];
30
+ clear(): void;
31
+ /**
32
+ * Retrieves the values for all keys in the query range.
33
+ *
34
+ * @param start - The first key in the range being queried
35
+ * @param length - The length of the query range
36
+ * @returns A list of entries, each describing the value for some subrange of the query.
37
+ * The entries are in the same order as the keys, and there is an entry for every key with a non `undefined` value.
38
+ */
39
+ getAll(start: K, length: number): RangeQueryEntry<K, V>[];
17
40
  /**
18
41
  * Retrieves the value for some prefix of the query range.
19
42
  *
20
43
  * @param start - The first key in the query range.
21
44
  * @param length - The length of the query range.
22
45
  * @returns A RangeQueryResult containing the value associated with `start`,
23
- * and the number of consecutive keys with that same value.
46
+ * and the number of consecutive keys with that same value (at least 1, at most `length`).
24
47
  */
25
- get(start: number, length: number): RangeQueryResult<T>;
48
+ getFirst(start: K, length: number): RangeQueryResult<K, V>;
26
49
  /**
27
50
  * Sets the value for a specified range.
28
51
  *
@@ -30,7 +53,7 @@ export declare class RangeMap<T> {
30
53
  * @param length - The length of the range.
31
54
  * @param value - The value to associate with the range.
32
55
  */
33
- set(start: number, length: number, value: T | undefined): void;
56
+ set(start: K, length: number, value: V | undefined): void;
34
57
  /**
35
58
  * Deletes values within a specified range, updating or removing existing entries.
36
59
  *
@@ -51,35 +74,31 @@ export declare class RangeMap<T> {
51
74
  * @param start - The start of the range to delete (inclusive).
52
75
  * @param length - The length of the range to delete.
53
76
  */
54
- delete(start: number, length: number): void;
55
- }
56
- /**
57
- * Represents a contiguous range of values in the RangeMap.
58
- * This interface is used internally and should not be exposed to consumers.
59
- */
60
- interface RangeEntry<T> {
77
+ delete(start: K, length: number): void;
78
+ clone(): RangeMap<K, V>;
61
79
  /**
62
- * The starting index of the range (inclusive).
80
+ * Returns a new map which contains the entries from both input maps.
63
81
  */
64
- readonly start: number;
65
- /**
66
- * The length of the range.
67
- */
68
- readonly length: number;
69
- /**
70
- * The value associated with this range.
71
- */
72
- readonly value: T;
82
+ static union<K, V>(a: RangeMap<K, V>, b: RangeMap<K, V>): RangeMap<K, V>;
83
+ private getIntersectingEntries;
84
+ private gt;
85
+ private ge;
86
+ private lt;
87
+ private le;
73
88
  }
74
89
  /**
75
90
  * Describes the result of a range query, including the value and length of the matching prefix.
76
91
  */
77
- export interface RangeQueryResult<T> {
92
+ export interface RangeQueryResult<K, V> {
93
+ /**
94
+ * The key for the first element in the range.
95
+ */
96
+ readonly start: K;
78
97
  /**
79
98
  * The value of the first key in the query range.
80
99
  * If no matching range is found, this will be undefined.
81
100
  */
82
- readonly value: T | undefined;
101
+ readonly value: V | undefined;
83
102
  /**
84
103
  * The length of the prefix of the query range which has the same value.
85
104
  * For example, if a RangeMap has the same value for keys 5, 6, and 7,
@@ -87,5 +106,8 @@ export interface RangeQueryResult<T> {
87
106
  */
88
107
  readonly length: number;
89
108
  }
90
- export {};
109
+ export interface RangeQueryEntry<K, V> extends RangeQueryResult<K, V> {
110
+ readonly value: V;
111
+ }
112
+ export declare function newIntegerRangeMap<V>(): RangeMap<number, V>;
91
113
  //# sourceMappingURL=rangeMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rangeMap.d.ts","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,qBAAa,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;gBAEvB,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE;IAInD;;;OAGG;IACI,aAAa,IAAI,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE;IAItD;;;;;;;OAOG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAiB9D;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI;IAsErE;;;;;;;;;;;;;;;;;;;OAmBG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAwDlD;AAED;;;GAGG;AACH,UAAU,UAAU,CAAC,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAE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E,MAAM,EAAE,MAAM,GAAG,IAAI;IAsBtC,KAAK,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAM9B;;OAEG;WACW,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAkB/E,OAAO,CAAC,sBAAsB;IAkC9B,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,EAAE;CAGV;AAiBD;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACrC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;IACpE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAE3D"}
@@ -2,21 +2,69 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { oob } from "@fluidframework/core-utils/internal";
5
+ import { assert, oob } from "@fluidframework/core-utils/internal";
6
+ import { BTree } from "@tylerbu/sorted-btree-es6";
6
7
  /**
7
- * RangeMap represents a mapping from integers to values of type T or undefined.
8
+ * RangeMap represents a mapping from keys of type K to values of type V or undefined.
9
+ * The set of all possible keys is assumed to be fully ordered,
10
+ * and for each key there should be a single next higher key.
8
11
  * The values for a range of consecutive keys can be changed or queried in a single operation.
12
+ * The structure of the keys is described by the `offsetKey` and `subtractKeys` functions provided in the constructor.
9
13
  */
10
14
  export class RangeMap {
11
- constructor(initialEntries) {
12
- this.entries = initialEntries ? [...initialEntries] : [];
15
+ /**
16
+ * @param offsetKey - Function which returns a new key which is `offset` keys after `key`.
17
+ * When `offset` is negative, the returned key should come before `key`.
18
+ *
19
+ * @param subtractKeys - Function which returns the difference between `b` and `a`.
20
+ * Offsetting `b` by this difference should return `a`.
21
+ * The difference can be infinite if `a` cannot be reached from `b` by offsetting,
22
+ * but the difference should still be positive if `a` is larger than `b` and negative if smaller.
23
+ */
24
+ constructor(offsetKey, subtractKeys) {
25
+ this.offsetKey = offsetKey;
26
+ this.subtractKeys = subtractKeys;
27
+ this.tree = new BTree(undefined, subtractKeys);
13
28
  }
14
29
  /**
15
- * Retrieves all entries from the rangeMap.
16
- * @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
30
+ * Retrieves all entries from the RangeMap.
17
31
  */
18
- getAllEntries() {
19
- return this.entries;
32
+ entries() {
33
+ const entries = [];
34
+ for (const [start, entry] of this.tree.entries()) {
35
+ entries.push({ start, length: entry.length, value: entry.value });
36
+ }
37
+ return entries;
38
+ }
39
+ clear() {
40
+ this.tree.clear();
41
+ }
42
+ /**
43
+ * Retrieves the values for all keys in the query range.
44
+ *
45
+ * @param start - The first key in the range being queried
46
+ * @param length - The length of the query range
47
+ * @returns A list of entries, each describing the value for some subrange of the query.
48
+ * The entries are in the same order as the keys, and there is an entry for every key with a non `undefined` value.
49
+ */
50
+ getAll(start, length) {
51
+ const entries = this.getIntersectingEntries(start, length);
52
+ if (entries.length === 0) {
53
+ return entries;
54
+ }
55
+ const firstEntry = entries[0] ?? oob();
56
+ const lengthBefore = this.subtractKeys(start, firstEntry.start);
57
+ if (lengthBefore > 0) {
58
+ entries[0] = { ...firstEntry, start, length: firstEntry.length - lengthBefore };
59
+ }
60
+ const lastEntry = entries[entries.length - 1] ?? oob();
61
+ const lastEntryKey = this.offsetKey(lastEntry.start, lastEntry.length - 1);
62
+ const lastQueryKey = this.offsetKey(start, length - 1);
63
+ const lengthAfter = this.subtractKeys(lastEntryKey, lastQueryKey);
64
+ if (lengthAfter > 0) {
65
+ entries[entries.length - 1] = { ...lastEntry, length: lastEntry.length - lengthAfter };
66
+ }
67
+ return entries;
20
68
  }
21
69
  /**
22
70
  * Retrieves the value for some prefix of the query range.
@@ -24,21 +72,35 @@ export class RangeMap {
24
72
  * @param start - The first key in the query range.
25
73
  * @param length - The length of the query range.
26
74
  * @returns A RangeQueryResult containing the value associated with `start`,
27
- * and the number of consecutive keys with that same value.
75
+ * and the number of consecutive keys with that same value (at least 1, at most `length`).
28
76
  */
29
- get(start, length) {
30
- for (const entry of this.entries) {
31
- if (entry.start > start) {
32
- return { value: undefined, length: Math.min(entry.start - start, length) };
77
+ getFirst(start, length) {
78
+ {
79
+ // We first check for an entry with a key less than or equal to `start`.
80
+ const entry = this.tree.getPairOrNextLower(start);
81
+ if (entry !== undefined) {
82
+ const entryKey = entry[0];
83
+ const { value, length: entryLength } = entry[1];
84
+ const entryLastKey = this.offsetKey(entryKey, entryLength - 1);
85
+ const overlappingLength = Math.min(this.subtractKeys(entryLastKey, start) + 1, length);
86
+ if (overlappingLength > 0) {
87
+ return { value, start, length: overlappingLength };
88
+ }
33
89
  }
34
- const lastRangeKey = entry.start + entry.length - 1;
35
- if (lastRangeKey >= start) {
36
- const overlapLength = lastRangeKey - start + 1;
37
- return { value: entry.value, length: Math.min(overlapLength, length) };
90
+ }
91
+ {
92
+ // There is no value associated with `start`.
93
+ // Now we need to determine how many of the following keys are also undefined.
94
+ const key = this.tree.nextHigherKey(start);
95
+ if (key !== undefined) {
96
+ const entryKey = key;
97
+ const lastQueryKey = this.offsetKey(start, length - 1);
98
+ if (this.le(entryKey, lastQueryKey)) {
99
+ return { value: undefined, start, length: this.subtractKeys(entryKey, start) };
100
+ }
38
101
  }
102
+ return { value: undefined, start, length };
39
103
  }
40
- // There were no entries intersecting the query range, so the entire query range has undefined value.
41
- return { value: undefined, length };
42
104
  }
43
105
  /**
44
106
  * Sets the value for a specified range.
@@ -48,65 +110,10 @@ export class RangeMap {
48
110
  * @param value - The value to associate with the range.
49
111
  */
50
112
  set(start, length, value) {
51
- if (value === undefined) {
52
- this.delete(start, length);
53
- return;
54
- }
55
- const end = start + length - 1;
56
- const newEntry = { start, length, value };
57
- let iBefore = -1;
58
- let iAfter = this.entries.length;
59
- for (const [i, entry] of this.entries.entries()) {
60
- const entryLastKey = entry.start + entry.length - 1;
61
- if (entryLastKey < start) {
62
- iBefore = i;
63
- }
64
- else if (entry.start > end) {
65
- iAfter = i;
66
- break;
67
- }
68
- }
69
- const numOverlappingEntries = iAfter - iBefore - 1;
70
- if (numOverlappingEntries === 0) {
71
- this.entries.splice(iAfter, 0, newEntry);
72
- return;
113
+ this.delete(start, length);
114
+ if (value !== undefined) {
115
+ this.tree.set(start, { value, length });
73
116
  }
74
- const iFirst = iBefore + 1;
75
- const firstEntry = this.entries[iFirst] ?? oob();
76
- const iLast = iAfter - 1;
77
- const lastEntry = this.entries[iLast] ?? oob();
78
- const lengthBeforeFirst = start - firstEntry.start;
79
- const lastEntryKey = lastEntry.start + lastEntry.length - 1;
80
- const lengthAfterLast = lastEntryKey - end;
81
- if (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {
82
- // The new entry fits in the middle of an existing entry.
83
- // We replace the existing entry with:
84
- // 1) the portion which comes before `newEntry`
85
- // 2) `newEntry`
86
- // 3) the portion which comes after `newEntry`
87
- this.entries.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {
88
- ...lastEntry,
89
- start: end + 1,
90
- length: lengthAfterLast,
91
- });
92
- return;
93
- }
94
- if (lengthBeforeFirst > 0) {
95
- this.entries[iFirst] = { ...firstEntry, length: lengthBeforeFirst };
96
- // The entry at `iFirst` is no longer overlapping with `newEntry`.
97
- iBefore = iFirst;
98
- }
99
- if (lengthAfterLast > 0) {
100
- this.entries[iLast] = {
101
- ...lastEntry,
102
- start: end + 1,
103
- length: lengthAfterLast,
104
- };
105
- // The entry at `iLast` is no longer overlapping with `newEntry`.
106
- iAfter = iLast;
107
- }
108
- const numContainedEntries = iAfter - iBefore - 1;
109
- this.entries.splice(iBefore + 1, numContainedEntries, newEntry);
110
117
  }
111
118
  /**
112
119
  * Deletes values within a specified range, updating or removing existing entries.
@@ -129,54 +136,90 @@ export class RangeMap {
129
136
  * @param length - The length of the range to delete.
130
137
  */
131
138
  delete(start, length) {
132
- const end = start + length - 1;
133
- let iBefore = -1;
134
- let iAfter = this.entries.length;
135
- for (const [i, entry] of this.entries.entries()) {
136
- const entryLastKey = entry.start + entry.length - 1;
137
- if (entryLastKey < start) {
138
- iBefore = i;
139
+ const lastDeleteKey = this.offsetKey(start, length - 1);
140
+ for (const { start: key, length: entryLength, value } of this.getIntersectingEntries(start, length)) {
141
+ this.tree.delete(key);
142
+ const lengthBefore = this.subtractKeys(start, key);
143
+ if (lengthBefore > 0) {
144
+ // A portion of this entry comes before the deletion range, so we reinsert that portion.
145
+ this.tree.set(key, { length: lengthBefore, value });
139
146
  }
140
- else if (entry.start > end) {
141
- iAfter = i;
142
- break;
147
+ const lastEntryKey = this.offsetKey(key, entryLength - 1);
148
+ const lengthAfter = this.subtractKeys(lastEntryKey, lastDeleteKey);
149
+ if (lengthAfter > 0) {
150
+ // A portion of this entry comes after the deletion range, so we reinsert that portion.
151
+ this.tree.set(this.offsetKey(lastDeleteKey, 1), { length: lengthAfter, value });
143
152
  }
144
153
  }
145
- const numOverlappingEntries = iAfter - iBefore - 1;
146
- if (numOverlappingEntries === 0) {
147
- // No entry will be removed
148
- return;
154
+ }
155
+ clone() {
156
+ const cloned = new RangeMap(this.offsetKey, this.subtractKeys);
157
+ cloned.tree = this.tree.clone();
158
+ return cloned;
159
+ }
160
+ /**
161
+ * Returns a new map which contains the entries from both input maps.
162
+ */
163
+ static union(a, b) {
164
+ assert(a.offsetKey === b.offsetKey && a.subtractKeys === b.subtractKeys, 0xaae /* Maps should have the same behavior */);
165
+ const merged = new RangeMap(a.offsetKey, a.subtractKeys);
166
+ // TODO: Is there a good pattern that lets us make `tree` readonly?
167
+ merged.tree = a.tree.clone();
168
+ for (const [key, value] of b.tree.entries()) {
169
+ // TODO: Handle key collisions
170
+ merged.tree.set(key, value);
149
171
  }
150
- const iFirst = iBefore + 1;
151
- const iLast = iAfter - 1;
152
- for (let i = iFirst; i <= iLast; ++i) {
153
- const entry = this.entries[i] ?? oob();
154
- const entryLastKey = entry.start + entry.length - 1;
155
- let isDirty = false;
156
- if (entry.start >= start && entryLastKey <= end) {
157
- // If the entry lies within the range to be deleted, remove it
158
- this.entries.splice(i, 1);
159
- }
160
- else {
161
- // If the entry partially or completely overlaps with the range to be deleted
162
- if (entry.start < start) {
163
- // Update the endpoint and length of the portion before the range to be deleted
164
- const lengthBefore = start - entry.start;
165
- this.entries[i] = { ...entry, length: lengthBefore };
166
- isDirty = true;
172
+ return merged;
173
+ }
174
+ getIntersectingEntries(start, length) {
175
+ const entries = [];
176
+ const lastQueryKey = this.offsetKey(start, length - 1);
177
+ {
178
+ const entry = this.tree.getPairOrNextLower(start);
179
+ if (entry !== undefined) {
180
+ const key = entry[0];
181
+ const { length: entryLength, value } = entry[1];
182
+ const lastEntryKey = this.offsetKey(key, entryLength - 1);
183
+ if (this.ge(lastEntryKey, start)) {
184
+ entries.push({ start: key, length: entryLength, value });
167
185
  }
168
- if (entryLastKey > end) {
169
- // Update the startpoint and length of the portion after the range to be deleted
170
- const newStart = end + 1;
171
- const newLength = entryLastKey - end;
172
- this.entries.splice(isDirty ? i + 1 : i, isDirty ? 0 : 1, {
173
- start: newStart,
174
- length: newLength,
175
- value: entry.value,
176
- });
186
+ }
187
+ }
188
+ {
189
+ let entry = this.tree.nextHigherPair(start);
190
+ while (entry !== undefined) {
191
+ const key = entry[0];
192
+ if (this.gt(key, lastQueryKey)) {
193
+ break;
177
194
  }
195
+ const { length: entryLength, value } = entry[1];
196
+ const lastEntryKey = this.offsetKey(key, entryLength - 1);
197
+ entries.push({ start: key, length: entryLength, value });
198
+ entry = this.tree.nextHigherPair(lastEntryKey);
178
199
  }
179
200
  }
201
+ return entries;
202
+ }
203
+ gt(a, b) {
204
+ return this.subtractKeys(a, b) > 0;
205
+ }
206
+ ge(a, b) {
207
+ return this.subtractKeys(a, b) >= 0;
208
+ }
209
+ lt(a, b) {
210
+ return this.subtractKeys(a, b) < 0;
180
211
  }
212
+ le(a, b) {
213
+ return this.subtractKeys(a, b) <= 0;
214
+ }
215
+ }
216
+ export function newIntegerRangeMap() {
217
+ return new RangeMap(offsetInteger, subtractIntegers);
218
+ }
219
+ function offsetInteger(key, offset) {
220
+ return key + offset;
221
+ }
222
+ function subtractIntegers(a, b) {
223
+ return a - b;
181
224
  }
182
225
  //# sourceMappingURL=rangeMap.js.map