@fluidframework/tree 2.12.0 → 2.13.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.
- package/CHANGELOG.md +136 -0
- package/api-report/tree.alpha.api.md +86 -10
- package/api-report/tree.beta.api.md +22 -10
- package/api-report/tree.legacy.alpha.api.md +22 -10
- package/api-report/tree.legacy.public.api.md +22 -10
- package/api-report/tree.public.api.md +22 -10
- package/dist/alpha.d.ts +11 -0
- package/dist/beta.d.ts +2 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +0 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -4
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js +8 -2
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.js +24 -4
- package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.js +14 -5
- package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +2 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +2 -0
- package/dist/shared-tree/index.d.ts +2 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +2 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +43 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +6 -3
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +3 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/transactionTypes.d.ts +105 -0
- package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
- package/dist/shared-tree/transactionTypes.js +13 -0
- package/dist/shared-tree/transactionTypes.js.map +1 -0
- package/dist/shared-tree/treeApi.d.ts +1 -25
- package/dist/shared-tree/treeApi.d.ts.map +1 -1
- package/dist/shared-tree/treeApi.js +4 -8
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +4 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +130 -15
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -0
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +3 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
- package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/jsonSchema.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +5 -2
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
- package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchema.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/dist/simple-tree/api/tree.d.ts +60 -0
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +2 -2
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +2 -1
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +2 -2
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +3 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.d.ts +2 -2
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js +2 -1
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts +2 -2
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js +2 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
- package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/objectNodeTypes.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +47 -1
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -5
- package/dist/util/index.js.map +1 -1
- package/dist/util/rangeMap.d.ts +72 -42
- package/dist/util/rangeMap.d.ts.map +1 -1
- package/dist/util/rangeMap.js +161 -151
- package/dist/util/rangeMap.js.map +1 -1
- package/dist/util/utils.d.ts +22 -1
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +10 -1
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +11 -0
- package/lib/beta.d.ts +2 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +0 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +0 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js +9 -3
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.js +24 -4
- package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.js +14 -5
- package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +2 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +2 -0
- package/lib/shared-tree/index.d.ts +2 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +46 -3
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +6 -3
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +3 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/transactionTypes.d.ts +105 -0
- package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
- package/lib/shared-tree/transactionTypes.js +10 -0
- package/lib/shared-tree/transactionTypes.js.map +1 -0
- package/lib/shared-tree/treeApi.d.ts +1 -25
- package/lib/shared-tree/treeApi.d.ts.map +1 -1
- package/lib/shared-tree/treeApi.js +1 -5
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +4 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +130 -15
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -0
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -0
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
- package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/jsonSchema.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +5 -2
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
- package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchema.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/lib/simple-tree/api/tree.d.ts +60 -0
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +2 -2
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +2 -1
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +2 -2
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.d.ts +2 -2
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js +2 -1
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts +2 -2
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js +2 -1
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
- package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/objectNodeTypes.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +47 -1
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +2 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/rangeMap.d.ts +72 -42
- package/lib/util/rangeMap.d.ts.map +1 -1
- package/lib/util/rangeMap.js +159 -146
- package/lib/util/rangeMap.js.map +1 -1
- package/lib/util/utils.d.ts +22 -1
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +8 -0
- package/lib/util/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
- package/src/feature-libraries/index.ts +0 -1
- package/src/feature-libraries/modular-schema/crossFieldQueries.ts +9 -9
- package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +13 -9
- package/src/feature-libraries/modular-schema/genericFieldKind.ts +4 -2
- package/src/feature-libraries/modular-schema/index.ts +1 -0
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +124 -31
- package/src/feature-libraries/modular-schema/modularChangeTypes.ts +12 -0
- package/src/feature-libraries/optional-field/optionalField.ts +34 -5
- package/src/feature-libraries/sequence-field/utils.ts +18 -7
- package/src/index.ts +11 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/index.ts +12 -2
- package/src/shared-tree/schematizingTreeView.ts +91 -2
- package/src/shared-tree/sharedTree.ts +9 -4
- package/src/shared-tree/transactionTypes.ts +125 -0
- package/src/shared-tree/treeApi.ts +1 -28
- package/src/shared-tree/treeCheckout.ts +147 -13
- package/src/shared-tree-core/sharedTreeCore.ts +1 -1
- package/src/simple-tree/api/index.ts +1 -0
- package/src/simple-tree/api/jsonSchema.ts +7 -0
- package/src/simple-tree/api/schemaFactory.ts +33 -6
- package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
- package/src/simple-tree/api/simpleSchema.ts +6 -1
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
- package/src/simple-tree/api/tree.ts +76 -4
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
- package/src/simple-tree/arrayNode.ts +7 -1
- package/src/simple-tree/core/treeNodeSchema.ts +51 -7
- package/src/simple-tree/index.ts +3 -0
- package/src/simple-tree/mapNode.ts +7 -1
- package/src/simple-tree/objectNode.ts +7 -1
- package/src/simple-tree/objectNodeTypes.ts +4 -1
- package/src/simple-tree/schemaTypes.ts +50 -1
- package/src/util/index.ts +2 -6
- package/src/util/rangeMap.ts +199 -189
- package/src/util/utils.ts +47 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
- package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
- package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
package/src/util/rangeMap.ts
CHANGED
|
@@ -6,229 +6,239 @@
|
|
|
6
6
|
import { oob } from "@fluidframework/core-utils/internal";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* TODO: We should avoid the direct exposure of RangeEntry. AB#7414
|
|
9
|
+
* RangeMap represents a mapping from integers to values of type T or undefined.
|
|
10
|
+
* The values for a range of consecutive keys can be changed or queried in a single operation.
|
|
12
11
|
*/
|
|
13
|
-
export
|
|
12
|
+
export class RangeMap<T> {
|
|
13
|
+
private readonly entries: RangeEntry<T>[];
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
value: T;
|
|
19
|
-
}
|
|
15
|
+
public constructor(initialEntries?: RangeEntry<T>[]) {
|
|
16
|
+
this.entries = initialEntries ? [...initialEntries] : [];
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
/**
|
|
22
|
-
* The result of a query about a range of keys.
|
|
23
|
-
*/
|
|
24
|
-
export interface RangeQueryResult<T> {
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
20
|
+
* Retrieves all entries from the rangeMap.
|
|
21
|
+
* @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
|
|
27
22
|
*/
|
|
28
|
-
|
|
23
|
+
public getAllEntries(): readonly RangeQueryResult<T>[] {
|
|
24
|
+
return this.entries;
|
|
25
|
+
}
|
|
29
26
|
|
|
30
27
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* Retrieves the value for some prefix of the query range.
|
|
29
|
+
*
|
|
30
|
+
* @param start - The first key in the query range.
|
|
31
|
+
* @param length - The length of the query range.
|
|
32
|
+
* @returns A RangeQueryResult containing the value associated with `start`,
|
|
33
|
+
* and the number of consecutive keys with that same value.
|
|
34
34
|
*/
|
|
35
|
-
length: number
|
|
36
|
-
|
|
35
|
+
public get(start: number, length: number): RangeQueryResult<T> {
|
|
36
|
+
for (const entry of this.entries) {
|
|
37
|
+
if (entry.start > start) {
|
|
38
|
+
return { value: undefined, length: Math.min(entry.start - start, length) };
|
|
39
|
+
}
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
start: number,
|
|
44
|
-
length: number,
|
|
45
|
-
): RangeQueryResult<T> {
|
|
46
|
-
for (const range of map) {
|
|
47
|
-
if (range.start > start) {
|
|
48
|
-
return { value: undefined, length: Math.min(range.start - start, length) };
|
|
41
|
+
const lastRangeKey = entry.start + entry.length - 1;
|
|
42
|
+
if (lastRangeKey >= start) {
|
|
43
|
+
const overlapLength = lastRangeKey - start + 1;
|
|
44
|
+
return { value: entry.value, length: Math.min(overlapLength, length) };
|
|
45
|
+
}
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// This range contains `start`.
|
|
54
|
-
const overlapLength = lastRangeKey - start + 1;
|
|
55
|
-
return { value: range.value, length: Math.min(overlapLength, length) };
|
|
56
|
-
}
|
|
48
|
+
// There were no entries intersecting the query range, so the entire query range has undefined value.
|
|
49
|
+
return { value: undefined, length };
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Sets the value for a specified range.
|
|
54
|
+
*
|
|
55
|
+
* @param start - The first key in the range being set.
|
|
56
|
+
* @param length - The length of the range.
|
|
57
|
+
* @param value - The value to associate with the range.
|
|
58
|
+
*/
|
|
59
|
+
public set(start: number, length: number, value: T | undefined): void {
|
|
60
|
+
if (value === undefined) {
|
|
61
|
+
this.delete(start, length);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const end = start + length - 1;
|
|
66
|
+
const newEntry: RangeEntry<T> = { start, length, value };
|
|
67
|
+
|
|
68
|
+
let iBefore = -1;
|
|
69
|
+
let iAfter = this.entries.length;
|
|
70
|
+
for (const [i, entry] of this.entries.entries()) {
|
|
71
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
72
|
+
if (entryLastKey < start) {
|
|
73
|
+
iBefore = i;
|
|
74
|
+
} else if (entry.start > end) {
|
|
75
|
+
iAfter = i;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
80
|
+
const numOverlappingEntries = iAfter - iBefore - 1;
|
|
81
|
+
if (numOverlappingEntries === 0) {
|
|
82
|
+
this.entries.splice(iAfter, 0, newEntry);
|
|
83
|
+
return;
|
|
78
84
|
}
|
|
79
|
-
}
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
const iFirst = iBefore + 1;
|
|
87
|
+
const firstEntry = this.entries[iFirst] ?? oob();
|
|
88
|
+
const iLast = iAfter - 1;
|
|
89
|
+
const lastEntry = this.entries[iLast] ?? oob();
|
|
90
|
+
const lengthBeforeFirst = start - firstEntry.start;
|
|
91
|
+
const lastEntryKey = lastEntry.start + lastEntry.length - 1;
|
|
92
|
+
const lengthAfterLast = lastEntryKey - end;
|
|
93
|
+
|
|
94
|
+
if (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {
|
|
95
|
+
// The new entry fits in the middle of an existing entry.
|
|
96
|
+
// We replace the existing entry with:
|
|
97
|
+
// 1) the portion which comes before `newEntry`
|
|
98
|
+
// 2) `newEntry`
|
|
99
|
+
// 3) the portion which comes after `newEntry`
|
|
100
|
+
this.entries.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {
|
|
101
|
+
...lastEntry,
|
|
102
|
+
start: end + 1,
|
|
103
|
+
length: lengthAfterLast,
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
83
107
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
map: RangeMap<T>,
|
|
89
|
-
start: number,
|
|
90
|
-
length: number,
|
|
91
|
-
value: T,
|
|
92
|
-
): void {
|
|
93
|
-
const end = start + length - 1;
|
|
94
|
-
const newEntry: RangeEntry<T> = { start, length, value };
|
|
95
|
-
|
|
96
|
-
let iBefore = -1;
|
|
97
|
-
let iAfter = map.length;
|
|
98
|
-
for (const [i, entry] of map.entries()) {
|
|
99
|
-
const entryLastKey = entry.start + entry.length - 1;
|
|
100
|
-
if (entryLastKey < start) {
|
|
101
|
-
iBefore = i;
|
|
102
|
-
} else if (entry.start > end) {
|
|
103
|
-
iAfter = i;
|
|
104
|
-
break;
|
|
108
|
+
if (lengthBeforeFirst > 0) {
|
|
109
|
+
this.entries[iFirst] = { ...firstEntry, length: lengthBeforeFirst };
|
|
110
|
+
// The entry at `iFirst` is no longer overlapping with `newEntry`.
|
|
111
|
+
iBefore = iFirst;
|
|
105
112
|
}
|
|
106
|
-
}
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
if (lengthAfterLast > 0) {
|
|
115
|
+
this.entries[iLast] = {
|
|
116
|
+
...lastEntry,
|
|
117
|
+
start: end + 1,
|
|
118
|
+
length: lengthAfterLast,
|
|
119
|
+
};
|
|
113
120
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const lengthAfterLast = lastEntryKey - end;
|
|
121
|
-
|
|
122
|
-
if (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {
|
|
123
|
-
// The new entry fits in the middle of an existing entry.
|
|
124
|
-
// We replace the existing entry with:
|
|
125
|
-
// 1) the portion which comes before `newEntry`
|
|
126
|
-
// 2) `newEntry`
|
|
127
|
-
// 3) the portion which comes after `newEntry`
|
|
128
|
-
map.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {
|
|
129
|
-
...lastEntry,
|
|
130
|
-
start: end + 1,
|
|
131
|
-
length: lengthAfterLast,
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
121
|
+
// The entry at `iLast` is no longer overlapping with `newEntry`.
|
|
122
|
+
iAfter = iLast;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const numContainedEntries = iAfter - iBefore - 1;
|
|
126
|
+
this.entries.splice(iBefore + 1, numContainedEntries, newEntry);
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Deletes values within a specified range, updating or removing existing entries.
|
|
131
|
+
*
|
|
132
|
+
* 1. If an entry is completely included in the deletion range, the whole entry will be deleted
|
|
133
|
+
* e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]
|
|
134
|
+
* map becomes [[1, 2]] after deletion
|
|
135
|
+
* (Note: the notation [a, b] represents start = a, end = b for simpler visualization, instead of `b`
|
|
136
|
+
* representing the length)
|
|
137
|
+
*
|
|
138
|
+
* 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted
|
|
139
|
+
* e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]
|
|
140
|
+
* map becomes [[1, 1], [5, 6]] after deletion
|
|
141
|
+
*
|
|
142
|
+
* 3. If an entry completely includes the deletion range, the original entry may be split into two.
|
|
143
|
+
* e.g.: map = [[1, 6]], delete range: [2, 4]
|
|
144
|
+
* map becomes [[1, 1], [5, 6]]
|
|
145
|
+
*
|
|
146
|
+
* @param start - The start of the range to delete (inclusive).
|
|
147
|
+
* @param length - The length of the range to delete.
|
|
148
|
+
*/
|
|
149
|
+
public delete(start: number, length: number): void {
|
|
150
|
+
const end = start + length - 1;
|
|
151
|
+
|
|
152
|
+
let iBefore = -1;
|
|
153
|
+
let iAfter = this.entries.length;
|
|
154
|
+
|
|
155
|
+
for (const [i, entry] of this.entries.entries()) {
|
|
156
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
157
|
+
if (entryLastKey < start) {
|
|
158
|
+
iBefore = i;
|
|
159
|
+
} else if (entry.start > end) {
|
|
160
|
+
iAfter = i;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
138
164
|
|
|
139
|
-
|
|
140
|
-
iBefore = iFirst;
|
|
141
|
-
}
|
|
165
|
+
const numOverlappingEntries = iAfter - iBefore - 1;
|
|
142
166
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
length: lengthAfterLast,
|
|
148
|
-
};
|
|
167
|
+
if (numOverlappingEntries === 0) {
|
|
168
|
+
// No entry will be removed
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
149
171
|
|
|
150
|
-
|
|
151
|
-
|
|
172
|
+
const iFirst = iBefore + 1;
|
|
173
|
+
const iLast = iAfter - 1;
|
|
174
|
+
|
|
175
|
+
for (let i = iFirst; i <= iLast; ++i) {
|
|
176
|
+
const entry = this.entries[i] ?? oob();
|
|
177
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
178
|
+
let isDirty = false;
|
|
179
|
+
|
|
180
|
+
if (entry.start >= start && entryLastKey <= end) {
|
|
181
|
+
// If the entry lies within the range to be deleted, remove it
|
|
182
|
+
this.entries.splice(i, 1);
|
|
183
|
+
} else {
|
|
184
|
+
// If the entry partially or completely overlaps with the range to be deleted
|
|
185
|
+
if (entry.start < start) {
|
|
186
|
+
// Update the endpoint and length of the portion before the range to be deleted
|
|
187
|
+
const lengthBefore = start - entry.start;
|
|
188
|
+
this.entries[i] = { ...entry, length: lengthBefore };
|
|
189
|
+
isDirty = true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (entryLastKey > end) {
|
|
193
|
+
// Update the startpoint and length of the portion after the range to be deleted
|
|
194
|
+
const newStart = end + 1;
|
|
195
|
+
const newLength = entryLastKey - end;
|
|
196
|
+
this.entries.splice(isDirty ? i + 1 : i, isDirty ? 0 : 1, {
|
|
197
|
+
start: newStart,
|
|
198
|
+
length: newLength,
|
|
199
|
+
value: entry.value,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
152
204
|
}
|
|
153
|
-
|
|
154
|
-
const numContainedEntries = iAfter - iBefore - 1;
|
|
155
|
-
map.splice(iBefore + 1, numContainedEntries, newEntry);
|
|
156
205
|
}
|
|
157
206
|
|
|
158
207
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* 1. If an entry is completely included in the deletion range, the whole entry will be deleted
|
|
162
|
-
* e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]
|
|
163
|
-
* map becomes [[1, 2]] after deletion
|
|
164
|
-
* (Note: the notation [a, b] represents start = a, end = b for simpler visiualization, instead of `b`
|
|
165
|
-
* representing the length)
|
|
166
|
-
*
|
|
167
|
-
* 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted
|
|
168
|
-
* e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]
|
|
169
|
-
* map becomes [[1, 1], [5, 6]] after deletion
|
|
170
|
-
*
|
|
171
|
-
* 3. If an entry completely includes the deletion range, the original entry may be split into two.
|
|
172
|
-
* e.g.: map = [[1, 6]], delete range: [2, 4]
|
|
173
|
-
* map becomes [[1, 1], [5, 6]]
|
|
174
|
-
*
|
|
175
|
-
* TODO: We may find ways to mitigate the code duplication between set and delete, and we need to better
|
|
176
|
-
* document the API. AB#7413
|
|
208
|
+
* Represents a contiguous range of values in the RangeMap.
|
|
209
|
+
* This interface is used internally and should not be exposed to consumers.
|
|
177
210
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
for (const [i, entry] of map.entries()) {
|
|
185
|
-
const entryLastKey = entry.start + entry.length - 1;
|
|
186
|
-
if (entryLastKey < start) {
|
|
187
|
-
iBefore = i;
|
|
188
|
-
} else if (entry.start > end) {
|
|
189
|
-
iAfter = i;
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
211
|
+
interface RangeEntry<T> {
|
|
212
|
+
/**
|
|
213
|
+
* The starting index of the range (inclusive).
|
|
214
|
+
*/
|
|
215
|
+
readonly start: number;
|
|
193
216
|
|
|
194
|
-
|
|
217
|
+
/**
|
|
218
|
+
* The length of the range.
|
|
219
|
+
*/
|
|
220
|
+
readonly length: number;
|
|
195
221
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
222
|
+
/**
|
|
223
|
+
* The value associated with this range.
|
|
224
|
+
*/
|
|
225
|
+
readonly value: T;
|
|
226
|
+
}
|
|
200
227
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// If the entry lies within the range to be deleted, remove it
|
|
211
|
-
if (entry.start >= start && entryLastKey <= end) {
|
|
212
|
-
map.splice(i, 1);
|
|
213
|
-
} else {
|
|
214
|
-
// If the entry partially or completely overlaps with the range to be deleted
|
|
215
|
-
if (entry.start < start) {
|
|
216
|
-
// Update the endpoint and length of the portion before the range to be deleted
|
|
217
|
-
const lengthBefore = start - entry.start;
|
|
218
|
-
map[i] = { ...entry, length: lengthBefore };
|
|
219
|
-
isDirty = true;
|
|
220
|
-
}
|
|
228
|
+
/**
|
|
229
|
+
* Describes the result of a range query, including the value and length of the matching prefix.
|
|
230
|
+
*/
|
|
231
|
+
export interface RangeQueryResult<T> {
|
|
232
|
+
/**
|
|
233
|
+
* The value of the first key in the query range.
|
|
234
|
+
* If no matching range is found, this will be undefined.
|
|
235
|
+
*/
|
|
236
|
+
readonly value: T | undefined;
|
|
221
237
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
length: newLength,
|
|
229
|
-
value: entry.value,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
238
|
+
/**
|
|
239
|
+
* The length of the prefix of the query range which has the same value.
|
|
240
|
+
* For example, if a RangeMap has the same value for keys 5, 6, and 7,
|
|
241
|
+
* a query about the range [5, 10] would give a result with length 3.
|
|
242
|
+
*/
|
|
243
|
+
readonly length: number;
|
|
234
244
|
}
|
package/src/util/utils.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface MapGetSet<K, V> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Make all transitive properties in T readonly
|
|
19
|
+
* Make all transitive properties in `T` readonly
|
|
20
20
|
*/
|
|
21
21
|
export type RecursiveReadonly<T> = {
|
|
22
22
|
readonly [P in keyof T]: RecursiveReadonly<T[P]>;
|
|
@@ -563,3 +563,49 @@ export function defineLazyCachedProperty<
|
|
|
563
563
|
});
|
|
564
564
|
return obj as typeof obj & { [P in K]: V };
|
|
565
565
|
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Copies a given property from one object to another if and only if the property is defined.
|
|
569
|
+
* @param source - The object to copy the property from.
|
|
570
|
+
* If `source` is undefined or does not have the property defined, then this function will do nothing.
|
|
571
|
+
* @param property - The property to copy.
|
|
572
|
+
* @param destination - The object to copy the property to.
|
|
573
|
+
* @remarks This function is useful for copying properties from one object to another while minimizing the presence of `undefined` values.
|
|
574
|
+
* If `property` is not present on `source` - or if `property` is present, but has a value of `undefined` - then this function will not modify `destination`.
|
|
575
|
+
* This is different from doing `destination.foo = source.foo`, which would define a `"foo"` property on `destination` with the value `undefined`.
|
|
576
|
+
*
|
|
577
|
+
* If the type of `source` is known to have `property`, then this function asserts that the type of `destination` has `property` as well after the call.
|
|
578
|
+
*
|
|
579
|
+
* This function first reads the property value (if present) from `source` and then sets it on `destination`, as opposed to e.g. directly copying the property descriptor.
|
|
580
|
+
* @privateRemarks The first overload of this function allows auto-complete to suggest property names from `source`, but by having the second overload we still allow for arbitrary property names.
|
|
581
|
+
*/
|
|
582
|
+
export function copyPropertyIfDefined<S extends object, K extends keyof S, D extends object>(
|
|
583
|
+
source: S | undefined,
|
|
584
|
+
property: K,
|
|
585
|
+
destination: D,
|
|
586
|
+
): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D;
|
|
587
|
+
export function copyPropertyIfDefined<
|
|
588
|
+
S extends object,
|
|
589
|
+
K extends string | number | symbol,
|
|
590
|
+
D extends object,
|
|
591
|
+
>(
|
|
592
|
+
source: S | undefined,
|
|
593
|
+
property: K,
|
|
594
|
+
destination: D,
|
|
595
|
+
): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D;
|
|
596
|
+
export function copyPropertyIfDefined<
|
|
597
|
+
S extends object,
|
|
598
|
+
K extends string | number | symbol,
|
|
599
|
+
D extends object,
|
|
600
|
+
>(
|
|
601
|
+
source: S | undefined,
|
|
602
|
+
property: K,
|
|
603
|
+
destination: D,
|
|
604
|
+
): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D {
|
|
605
|
+
if (source !== undefined) {
|
|
606
|
+
const value = (source as { [P in K]?: unknown })[property];
|
|
607
|
+
if (value !== undefined) {
|
|
608
|
+
(destination as { [P in K]: unknown })[property] = value;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import type { ChangesetLocalId, RevisionTag } from "../core/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* A unique ID allocator that returns the output ID for the same input ID.
|
|
8
|
-
*/
|
|
9
|
-
export interface MemoizedIdRangeAllocator {
|
|
10
|
-
/**
|
|
11
|
-
* A unique ID allocator that returns the output ID for the same input ID.
|
|
12
|
-
*
|
|
13
|
-
* "The same" here includes cases where a prior call allocated a range of IDs that partially or fully overlap with the
|
|
14
|
-
* current call.
|
|
15
|
-
* @param revision - The revision associated with the range of IDs to allocate.
|
|
16
|
-
* @param startId - The first ID to allocate.
|
|
17
|
-
* @param count - The number of IDs to allocate. Interpreted as 1 if undefined.
|
|
18
|
-
*/
|
|
19
|
-
allocate(revision: RevisionTag | undefined, startId: ChangesetLocalId, count?: number): IdRange[];
|
|
20
|
-
/**
|
|
21
|
-
* Allocates a new range of IDs.
|
|
22
|
-
*
|
|
23
|
-
* @param count - The number of IDs to allocate. Interpreted as 1 if undefined.
|
|
24
|
-
*/
|
|
25
|
-
mint(count?: number): ChangesetLocalId;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*/
|
|
29
|
-
export interface IdRange {
|
|
30
|
-
readonly first: ChangesetLocalId;
|
|
31
|
-
readonly count: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
*/
|
|
35
|
-
export declare const MemoizedIdRangeAllocator: {
|
|
36
|
-
fromNextId(nextId?: number): MemoizedIdRangeAllocator;
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=memoizedIdRangeAllocator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoizedIdRangeAllocator.d.ts","sourceRoot":"","sources":["../../src/feature-libraries/memoizedIdRangeAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAUtE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;;;;;;OAQG;IACH,QAAQ,CACP,QAAQ,EAAE,WAAW,GAAG,SAAS,EACjC,OAAO,EAAE,gBAAgB,EACzB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,EAAE,CAAC;IACb;;;;OAIG;IACH,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACvC;AAED;GACG;AACH,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;GACG;AACH,eAAO,MAAM,wBAAwB;wBACjB,MAAM,GAAO,wBAAwB;CA4DxD,CAAC"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.MemoizedIdRangeAllocator = void 0;
|
|
8
|
-
const index_js_1 = require("../util/index.js");
|
|
9
|
-
/**
|
|
10
|
-
*/
|
|
11
|
-
exports.MemoizedIdRangeAllocator = {
|
|
12
|
-
fromNextId(nextId = 0) {
|
|
13
|
-
const rangeMap = new Map();
|
|
14
|
-
let _nextId = nextId;
|
|
15
|
-
return {
|
|
16
|
-
allocate(key, startId, length) {
|
|
17
|
-
let count = length ?? 1;
|
|
18
|
-
const out = [];
|
|
19
|
-
const ranges = (0, index_js_1.getOrAddEmptyToMap)(rangeMap, key);
|
|
20
|
-
let currId = startId;
|
|
21
|
-
while (count > 0) {
|
|
22
|
-
const firstRange = (0, index_js_1.getFirstEntryFromRangeMap)(ranges, currId, count);
|
|
23
|
-
if (firstRange === undefined) {
|
|
24
|
-
const newId = _nextId;
|
|
25
|
-
_nextId += count;
|
|
26
|
-
(0, index_js_1.setInRangeMap)(ranges, currId, count, newId);
|
|
27
|
-
out.push({ first: (0, index_js_1.brand)(newId), count });
|
|
28
|
-
count = 0;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
const idRange = {
|
|
32
|
-
first: (0, index_js_1.brand)(firstRange.value),
|
|
33
|
-
count: firstRange.length,
|
|
34
|
-
};
|
|
35
|
-
if (currId < firstRange.start) {
|
|
36
|
-
const countToAdd = firstRange.start - currId;
|
|
37
|
-
(0, index_js_1.setInRangeMap)(ranges, currId, countToAdd, _nextId);
|
|
38
|
-
out.push({ first: (0, index_js_1.brand)(_nextId), count: countToAdd });
|
|
39
|
-
_nextId += countToAdd;
|
|
40
|
-
currId += countToAdd;
|
|
41
|
-
count -= countToAdd;
|
|
42
|
-
}
|
|
43
|
-
else if (firstRange.start < currId) {
|
|
44
|
-
const countToTrim = currId - firstRange.start;
|
|
45
|
-
idRange.first = (0, index_js_1.brand)(idRange.first + countToTrim);
|
|
46
|
-
idRange.count -= countToTrim;
|
|
47
|
-
}
|
|
48
|
-
if (idRange.count > count) {
|
|
49
|
-
idRange.count = count;
|
|
50
|
-
}
|
|
51
|
-
else if (idRange.count < count &&
|
|
52
|
-
firstRange.value + firstRange.length === _nextId) {
|
|
53
|
-
// The existing range can be extended
|
|
54
|
-
_nextId += count - idRange.count;
|
|
55
|
-
firstRange.length = count;
|
|
56
|
-
idRange.count = count;
|
|
57
|
-
}
|
|
58
|
-
out.push(idRange);
|
|
59
|
-
count -= idRange.count;
|
|
60
|
-
currId += idRange.count;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return out;
|
|
64
|
-
},
|
|
65
|
-
mint(length) {
|
|
66
|
-
const count = length ?? 1;
|
|
67
|
-
const out = _nextId;
|
|
68
|
-
_nextId += count;
|
|
69
|
-
return (0, index_js_1.brand)(out);
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=memoizedIdRangeAllocator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoizedIdRangeAllocator.js","sourceRoot":"","sources":["../../src/feature-libraries/memoizedIdRangeAllocator.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ChangesetLocalId, RevisionTag } from \"../core/index.js\";\nimport {\n\ttype Mutable,\n\ttype RangeMap,\n\tbrand,\n\tgetFirstEntryFromRangeMap,\n\tgetOrAddEmptyToMap,\n\tsetInRangeMap,\n} from \"../util/index.js\";\n\n/**\n * A unique ID allocator that returns the output ID for the same input ID.\n */\nexport interface MemoizedIdRangeAllocator {\n\t/**\n\t * A unique ID allocator that returns the output ID for the same input ID.\n\t *\n\t * \"The same\" here includes cases where a prior call allocated a range of IDs that partially or fully overlap with the\n\t * current call.\n\t * @param revision - The revision associated with the range of IDs to allocate.\n\t * @param startId - The first ID to allocate.\n\t * @param count - The number of IDs to allocate. Interpreted as 1 if undefined.\n\t */\n\tallocate(\n\t\trevision: RevisionTag | undefined,\n\t\tstartId: ChangesetLocalId,\n\t\tcount?: number,\n\t): IdRange[];\n\t/**\n\t * Allocates a new range of IDs.\n\t *\n\t * @param count - The number of IDs to allocate. Interpreted as 1 if undefined.\n\t */\n\tmint(count?: number): ChangesetLocalId;\n}\n\n/**\n */\nexport interface IdRange {\n\treadonly first: ChangesetLocalId;\n\treadonly count: number;\n}\n\n/**\n */\nexport const MemoizedIdRangeAllocator = {\n\tfromNextId(nextId: number = 0): MemoizedIdRangeAllocator {\n\t\tconst rangeMap: Map<RevisionTag | undefined, RangeMap<number>> = new Map();\n\t\tlet _nextId = nextId;\n\t\treturn {\n\t\t\tallocate(key: string | number | undefined, startId: number, length?: number): IdRange[] {\n\t\t\t\tlet count = length ?? 1;\n\t\t\t\tconst out: IdRange[] = [];\n\t\t\t\tconst ranges = getOrAddEmptyToMap(rangeMap, key);\n\t\t\t\tlet currId = startId;\n\t\t\t\twhile (count > 0) {\n\t\t\t\t\tconst firstRange = getFirstEntryFromRangeMap(ranges, currId, count);\n\t\t\t\t\tif (firstRange === undefined) {\n\t\t\t\t\t\tconst newId = _nextId;\n\t\t\t\t\t\t_nextId += count;\n\t\t\t\t\t\tsetInRangeMap(ranges, currId, count, newId);\n\t\t\t\t\t\tout.push({ first: brand(newId), count });\n\t\t\t\t\t\tcount = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst idRange: Mutable<IdRange> = {\n\t\t\t\t\t\t\tfirst: brand(firstRange.value),\n\t\t\t\t\t\t\tcount: firstRange.length,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif (currId < firstRange.start) {\n\t\t\t\t\t\t\tconst countToAdd = firstRange.start - currId;\n\t\t\t\t\t\t\tsetInRangeMap(ranges, currId, countToAdd, _nextId);\n\t\t\t\t\t\t\tout.push({ first: brand(_nextId), count: countToAdd });\n\t\t\t\t\t\t\t_nextId += countToAdd;\n\t\t\t\t\t\t\tcurrId += countToAdd;\n\t\t\t\t\t\t\tcount -= countToAdd;\n\t\t\t\t\t\t} else if (firstRange.start < currId) {\n\t\t\t\t\t\t\tconst countToTrim = currId - firstRange.start;\n\t\t\t\t\t\t\tidRange.first = brand((idRange.first as number) + countToTrim);\n\t\t\t\t\t\t\tidRange.count -= countToTrim;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (idRange.count > count) {\n\t\t\t\t\t\t\tidRange.count = count;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tidRange.count < count &&\n\t\t\t\t\t\t\tfirstRange.value + firstRange.length === _nextId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// The existing range can be extended\n\t\t\t\t\t\t\t_nextId += count - idRange.count;\n\t\t\t\t\t\t\tfirstRange.length = count;\n\t\t\t\t\t\t\tidRange.count = count;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tout.push(idRange);\n\t\t\t\t\t\tcount -= idRange.count;\n\t\t\t\t\t\tcurrId += idRange.count;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn out;\n\t\t\t},\n\t\t\tmint(length?: number): ChangesetLocalId {\n\t\t\t\tconst count = length ?? 1;\n\t\t\t\tconst out = _nextId;\n\t\t\t\t_nextId += count;\n\t\t\t\treturn brand(out);\n\t\t\t},\n\t\t};\n\t},\n};\n"]}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import type { ChangesetLocalId, RevisionTag } from "../core/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* A unique ID allocator that returns the output ID for the same input ID.
|
|
8
|
-
*/
|
|
9
|
-
export interface MemoizedIdRangeAllocator {
|
|
10
|
-
/**
|
|
11
|
-
* A unique ID allocator that returns the output ID for the same input ID.
|
|
12
|
-
*
|
|
13
|
-
* "The same" here includes cases where a prior call allocated a range of IDs that partially or fully overlap with the
|
|
14
|
-
* current call.
|
|
15
|
-
* @param revision - The revision associated with the range of IDs to allocate.
|
|
16
|
-
* @param startId - The first ID to allocate.
|
|
17
|
-
* @param count - The number of IDs to allocate. Interpreted as 1 if undefined.
|
|
18
|
-
*/
|
|
19
|
-
allocate(revision: RevisionTag | undefined, startId: ChangesetLocalId, count?: number): IdRange[];
|
|
20
|
-
/**
|
|
21
|
-
* Allocates a new range of IDs.
|
|
22
|
-
*
|
|
23
|
-
* @param count - The number of IDs to allocate. Interpreted as 1 if undefined.
|
|
24
|
-
*/
|
|
25
|
-
mint(count?: number): ChangesetLocalId;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*/
|
|
29
|
-
export interface IdRange {
|
|
30
|
-
readonly first: ChangesetLocalId;
|
|
31
|
-
readonly count: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
*/
|
|
35
|
-
export declare const MemoizedIdRangeAllocator: {
|
|
36
|
-
fromNextId(nextId?: number): MemoizedIdRangeAllocator;
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=memoizedIdRangeAllocator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoizedIdRangeAllocator.d.ts","sourceRoot":"","sources":["../../src/feature-libraries/memoizedIdRangeAllocator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAUtE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;;;;;;OAQG;IACH,QAAQ,CACP,QAAQ,EAAE,WAAW,GAAG,SAAS,EACjC,OAAO,EAAE,gBAAgB,EACzB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,EAAE,CAAC;IACb;;;;OAIG;IACH,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACvC;AAED;GACG;AACH,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;GACG;AACH,eAAO,MAAM,wBAAwB;wBACjB,MAAM,GAAO,wBAAwB;CA4DxD,CAAC"}
|